# Aurelia DI injection and inheritance in typescript

**URL:** <https://discourse.aurelia.io/t/aurelia-di-injection-and-inheritance-in-typescript/1667>\
**Category:** Framework Knowledge\
**Created:** [September 25, 2018, 6:42am UTC](https://discourse.aurelia.io/t/aurelia-di-injection-and-inheritance-in-typescript/1667 "2018-09-25T06:42:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cluka](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/cluka/32/2364_2.png) [@cluka](https://discourse.aurelia.io/u/cluka)\
**Post date:** [September 25, 2018, 6:42am UTC](https://discourse.aurelia.io/t/aurelia-di-injection-and-inheritance-in-typescript/1667/1 "2018-09-25T06:42:27Z")

</div>

Hi,  
How does DI work in inheritance?  
Ie. let’s take this example (I use Typescript):

```auto
@autoinject
export abstract class HttpServiceBase {
    constructor (protected httpClient: HttpClient) {
    }
}

@autoinject
export class UserService extends HttpServiceBase {
    public getAllUsers():Promise<UserModel> {
        return this.httpClinet.fetch(....) ///implementation details are not important here
    }
}

```

and the usage:

```auto
export class NewUserVM {
    constructor (private service: UserService) {}

   async activate() {
        this.model = await this.service.getAllUsers();
    }
}

```

This throws an exception at run-time when I try to use httpClient, because I forgot to write the constructor in the derived class, so the HttpClient is not being injected.  
I know that in Typescript, if the derived class doesn’t specify constructor, the constructor is inherited.

1. So why does it not work?
2. Also, how can I make all my service instance that derive from HttpServiceBase transient when i use @autoinject?
3. Can I somehow enforce the ts-compiler/vscode-ide to detect missing constructor implementation in derived class and throw an error at compile-time, ts-lint maybe?

Thanks
