It is possible to lazily resolve a component in Castle Windsor by registering LazyOfTComponentLoader in the container and resolving a Lazy<T>
as specified here:
container.Register(
Component.For<ILazyComponentLoader>().ImplementedBy<LazyOfTComponentLoader>(),
Component.For<ISomeService>().ImplementedBy<ServiceImpl>().LifestyleTransient()
);
var lazy = container.Resolve<Lazy<ISomeService>>();
lazy.Value.DoSomething();
However, is it possible to register a component in the container so that it is always resolved as a Lazy<T>
without the need to specify Lazy in the resolve call?
Specifically, I'm wondering how to inject Lazy components into controllers in an MVC project when using constructor injection.
EDIT: You can specify Lazy<ISomeService> someService
as a parameter in the controller's constructor as can be seen here. However, is there a way of ensuring that a component is resolved lazily through the registration process?