Is possible to force automaticly use LazyResolve in constructor injection?

Oct 15, 2015 at 5:42 PM
Hello everyone,

So i've started my adventure with ServiceStack, so... also adventure with Funq.
My problem is similar to mentioned in topic i already read in discussions here, but i need to be sure that is no better way that i figured out.
From the background, in my previous project i got used to Unity container. In some cases i need to pass Func<Foo> instead of Foo as parameter of constuctor (of course, perviously "Foo" type is registered in container). It means that Func<Foo> is constructor injected. In Unity (with assumption that Foo has parameterless constructor!) it is made automaticly. It means, that with registration:

container.Register<Foo>(); (* in funq RegisterAutoWired)
container.Register<MyClass>(); (* in funq RegisterAutoWired)

with MyClass constructor signature: public MyClass(Foo foo) { ... }
i can without any registration or extenssion change signature described above to: public MyClass(Func<Foo> fooFactory) { ... }

and with:

container.Resolve<MyClass>();

everything will work fine, without any "resolution exception".


From my analysis of Funq's method signatures and community articles and discussions, there is no direct way to do this like in Unity. So my registration code in Funq is enriched with another registration:

container.Register<Func<Foo>>(c => c.LazyResolve<Foo>());

and everything works fine. My question is: can I make it better? (or from another side, like in topic title: can I force somehow (attribute?) to force Funq to use "lazy resolver" instead of "default resolver" for constructor injection?)
(imho - the power of funq performance is from that it (funq) not assume some scenarios, the registration of type must be directry match to resolving type, but perhaps... i don't know about sth?)

Big thanks for any kind of help (voice in thread).