-
Notifications
You must be signed in to change notification settings - Fork 712
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
Allow toDynamicValue to access the current context #351
Comments
Note: I'm not sure of the "module" terminology. I made it up, but a more experienced programmer may use a more fitting name. |
I think we can achieve this in an easier way: kernel.bind<WeaponComponentModel>(RSRCIDS.module).toDynamicValue((context: interfaces.Context) => {
return module_factory({
schema: context.kernel.get<IJsonSchema>(RSRCIDS.schema)
});
});
// usage:
const module = context.kernel.get<WeaponComponentModel>(RSRCIDS.module); Notice how we used: .toDynamicValue((context: interfaces.Context) => { /**/ }); Instead of: .toDynamicValue(() => { /**/ }); This is not possible at the moment but it is easy to implement 😄 I will try to implement it as soon as I can but might take me over a week because I have too much work at the moment with other stuff... Also check the recipe for Injecting dependencies into a function. |
This has been implemented by #352 and will be released soon |
* Update interfaces.ts * Update binding.ts * Update resolver.ts * Update inversify.test.ts * Update resolver.test.ts * Update binding_to_syntax.test.ts * Update binding_to_syntax.ts * Update value_injection.md * Update binding.ts * fixed issues with dynamic value injection and context support
This is perfect ! You are working so fast ! |
Thanks! I will try to do another release tonight I'm closing this issue now 😄 |
Expected Behavior
Still using Inversify. Works great so far, but I feel something is missing in the range of possible services.
I'm trying to do functional programming, using pure functions and not using classes (no state + considered harmful in javascript)
However, my modules still need injected dependencies.
With inversify, we can declare a range of ressources, from the simplest to the more complex
Current Behavior
I'm forced to use a factory:
Possible Solution
A simpler "module" service, half-way between dynamic values and factories, but not a class:
I'm still using a factory, but calling code doesn't have to be aware of it.
Steps to Reproduce (for bugs)
n/a
Context
trying to do functional programming, using pure functions and not using classes (no state + considered harmful in javascript)
The text was updated successfully, but these errors were encountered: