How to resolve type with dependency that is known only runtime? #175
-
How to resolve a type A which depends on instance of type B, but B can be constructed only runtime from the user input? Usually DI containers do that by injecting into user class Func<B,A> and in the implementation of Func<B,A> you can do something like A FactoryMethod(B b)
{
return container.Resolve<A>(new DependencyOverride<B>(b);
} This tells the container to use provided B instance when resolving the graph, instead of looking for registration of type B in the container. |
Beta Was this translation helpful? Give feedback.
Answered by
YairHalberstadt
Dec 14, 2021
Replies: 1 comment 7 replies
-
What does the user input look like? |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
ekalchev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does the user input look like?