-
-
Notifications
You must be signed in to change notification settings - Fork 127
Open
Description
net6, DryIoc 5.4.3
Hi!
I can't find the way to reuse depencency A when using creation Func for B.
My use case is this:
- A is other service client that has some heavy initialization logic in constructor and it will be ok to register A as singletone.
- B is client wrapper with string arg in constructor that specify user for A.
currently DryIoc calls A constructor every time getB called.
Is there a way to reuse A instance in creating B?
P.S. I saw docs for Func wrapper but asResolutionCall does not do the job.
using DryIoc;
var dc = new Container(
r => r
.WithMicrosoftDependencyInjectionRules()
.WithDefaultIfAlreadyRegistered(IfAlreadyRegistered.Throw)
.WithConcreteTypeDynamicRegistrations()
.WithIgnoringReuseForFuncWithArgs());
dc.Register<A>(reuse: Reuse.Singleton);
dc.Register<B>();
var getB = dc.Resolve<Func<string, B>>();
getB("1");
getB("2");
class A
{
public A()
=> Console.WriteLine("A created");
}
class B
{
public B(A a, string s) {}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels