-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DI issue - Injectable extending Injectable #1338
Comments
So what is the output of this code snippet: @Injectable()
export class Service {
constructor (@Inject('Value1') value: number) {
console.log(`Service1 -> ${value}`)
}
}
@Injectable()
export class ServiceCustom extends Service {
constructor (@Inject('Value2') value: number) {
super(value)
console.log(`Service2 -> ${value}`)
}
} This explanation:
is not clear enough, since "2" value = |
Hi Kamil, sry that Anyways there should be one output line Issue is that with this setup, instance of |
Are you able to create a small reproduction repository? It would help a lot |
Pls check here: |
More understandable example here as it cannot resolve @Injectable()
export class Service {
constructor (@Inject('Value1') value: number) {
}
}
@Injectable()
export class ServiceCustom extends Service {
constructor (@Inject('Value2') value: number) {
super(value)
}
}
@Module({
providers: [
{ provide: 'Value1', useValue: 1 },
Service
]
})
export class ModuleWithBaseServiceBehaviour {
}
@Module({
providers: [
{ provide: 'Value2', useValue: 2 },
{ provide: Service, useClass: ServiceCustom }
]
})
export class ModuleThatOverridesBaseServiceBehaviour {
}
@Module({
imports: [
ModuleWithBaseServiceBehaviour,
ModuleThatOverridesBaseServiceBehaviour
]
})
export class AppModule {
}
|
Fixed by #1345, thanks for reporting! |
Fixed in 5.5.0 :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hey guys,
We have around 60 dynamic modules imported into root module. These modules share most of the common behaviour / services, but few of them would like to do some overrides / customisation of common behaviour / services.
We've done it in a way where each of these dynamic modules creates own instances of common services (has it in providers), and whichever module would like to change common behaviour would extend the base service, and provide it like
{ provider: SomeService, useClass: MyCustomService }
whereMyCustomService extends SomeService
. We've encountered an issue with injecting dependencies into constructors of these classes.Actual reasoning behind this approach is quite complex, but pls check short example below.
Current behavior
Both modules below are imported into one root module.
Both
Service
andServiceCustom
got injected value2
, so dependencies fromService
were injected in toServiceCustom
.Expected behavior
If I am extending an injectable class and providing this custom class in different module under same injection token, I would expect that both constructors have dependecies injected correctly.
Minimal reproduction of the problem with instructions
see example above
Environment
The text was updated successfully, but these errors were encountered: