GenericFactory, get current requested type, like it was possible in StructureMap
See original GitHub issueHi, I know it’s not the best solution, but we have exactly that use case:
_.For(typeof(IFoo<>))
.Use(x =>
{
var ParamType = x.BuildStack.Current.RequestedType
.GetGenericArguments()[0];
return BuildUsingFooFactory(ParamType);
});
}
Is there a way to get the information of the current requested type, like it was possible with StructureMap?
This question is quite similar, but unfortunately it has no answer: https://stackoverflow.com/questions/68832353/how-can-i-get-the-requested-type-in-a-usectx-factory-func-in-lamar-5 Br
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Registering Method on Generic Factory with StructureMap
Current.RequestedType .GetGenericArguments()[0]; return BuildUsingFooFactory(ParamType); }); } private object BuildUsingFooFactory(Type ...
Read more >Generic Types
At the first request for that interface, StructureMap will run through its "missing family policies", one of which is to try to find...
Read more >Dependency Injection of Open Generics via factory #41050
TypedImplementationFactory { get; } + /// <summary> + /// Initializes a new instance of ... The type parameter is the requested serviceType.
Read more >structuremap ObjectFactory.GetAllInstances<IHandle<TEvent ...
Coding example for the question structuremap ObjectFactory. ... them to the correct handler type and it get's a bit tricky.... a possible solution...
Read more >ploeh blog danish software design
Only in Part 4 do you get extensive coverage of various DI ... can reuse them as much as you'd like, but only...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@rizi Sorry for being slow here, yes, just throw new NotSupportedException() in those methods. If I get around to it, I can finally formalize this pattern a bit. It comes up a couple times a year.
You can use a custom
Instance
type for the parent, open type, then override theCloseType()
method to return a subtype of LambaInstance that then calls through to your factory.So something like: