-
Notifications
You must be signed in to change notification settings - Fork 33
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
Injecting values at runtime #156
Comments
Hi, I've discovered this DI framework 5 min. ago, so I'm not an expert :) I've changed the line from
to
|
Hi Guys, I meant to comment on this earlier but life has a funny way of going sideways. The reason david specific syntax doesn't work is because grace only looks in the extra data context as a last resort. Paul's syntax is correct because you're telling Grace hey I'm commiting to passing in a Context so Grace knows to use the instance that is passed. To go along with Paul's suggestion I'm also going to add a little code to make this syntax possible as well c.ExportFactory<IInjectionContext,Func<Context>,Context>((injectionContext, instanceFactory) =>
(Context)injectionContext.Values.FirstOrDefault(v => v is Context) ?? instanceFactory()); This basically adds an override export that will pull the Context from the injection context or generate it if it doesn't exist. |
I'm going to release 6.3.4 with this fix and close this issue. |
Is it possible to resolve a type from the container, change some properties on it, then use that instance when resolving other types that take the first type as a dependency, rather than returning a new instance?
From what Intellisense suggests, the
extraData
parameter onLocate()
should be my friend, so here's the basics of a test that demonstrates what I want to achieve (I've attached a proof-of-concept):However, the test fails as the context I sent to Grace is not the same context that is injected into my handler (I've tried modifying the test to use Assert.Same on the two contexts, but it fails also).
So, is what I am trying to do possible, or am I just doing it wrong?
grace-injectable-values.zip
The text was updated successfully, but these errors were encountered: