-
Notifications
You must be signed in to change notification settings - Fork 173
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
How to inject a mix of runtime value and normal dependencies #193
Comments
you can register value in container const SomeToken:InjectionToken<string> = "MyToken";
class Service{
constructor(
@inject(ServiceA) private dependencyA: ServiceA,
@inject(ServiceA) private dependencyB: ServiceB,
@inject(SomeToken) runtimeValue: string,
)
}
container.registerInstance(SomeToken, "runtimeValue");
container.resolve(SomeToken); // runtimeValue
container.resolve(Service); // Service instance https://github.com/microsoft/tsyringe#injecting-primitive-values-named-injection |
Thank you. Registering the runtime value at runtime just before resolving looks a bit weird but I reckon that's the best we can get. |
I think that |
I'd like to implement something like the following:
A orchestration service whose constructor accepts dependency services (can be injected using
@inject
decorator) and a runtime value:And then I can somehow resolve the instance using the runtime value:
I think I have two problems here:
Any suggestion / help will be really appreciated.
The text was updated successfully, but these errors were encountered: