-
Notifications
You must be signed in to change notification settings - Fork 723
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
toDynamicValue and caching #357
Comments
I need to think more about the possible implementation of this. I will confirm soon If I can implement something to sove this. For the moment you can use a closure to create a "singleton dynamic value": bind<AdventureArchetypeModel>(RSRCIDS.model).toDynamicValue((function() {
var cache = null;
return (context: interfaces.Context) => {
if (cache !== null) {
return cache;
} else {
return factory({
schema: context.kernel.get<IJsonSchemaExtended>(RSRCIDS.schema)
});
}
};
})()); Note that I haven't actually tested this but my guess is that it will work... |
A solution could be to create a new type of binding as I proposed in #351. The "dynamic value" semantic has its own meaning. |
What we are missing is support for kernel.bind<AdventureArchetypeModel>(RSRCIDS.model)
.toDynamicValue((context: interfaces.Context) => {
return factory({ schema: context.kernel.get<IJsonSchemaExtended>(RSRCIDS.schema) });
}).inSingletonScope(); I will add support for this ASAP. |
Great ! So the caching would be configurable, even better. But I'd like you to elaborate about this "singleton scope". I guess it means that for a given kernel state, the same resource identifier will return the same resource (singleton). Do you confirm ? Can you elaborate on the caching mechanism ? Is there a documentation entry for this feature ? As usual, I'm impressed at your reactivity ! |
I have improved the page about scope in the wiki: About
|
Implemented by #360 I will release this ASAP 😄 |
Tested it just now. Works perfectly 👍 |
Expected Behavior
I converted my useless model factories to dynamic values (.toDynamicValue) as suggested in #351. I expect the bound resources to be cached.
Current Behavior
The bound resources are not cached. Underlying factory is called each get() (and other factories in cascade)
Possible Solution
If it's by design (well... dynamic value), then using dynamic values may not be a proper solution to #351
Context
Still 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: