I use TypeFactoryFacility with a common factory to avoid creating components of the container instance until they are needed. The general factory is as follows:
public interface IGenericFactory<T> {
T Create();
void Release(T dummyComponent);
}
Later I use it as follows:
container.Register(
Component.For<IGenericFactory<IUtilityService>>().AsFactory());
container.Register(
Component.For<IUtilityService>().ImplementedBy<UtilityService>()
.OnCreate(WireUpAttibutes).LifeStyle.PerWebRequest);
Then I use IGenericFactory<IUtilityService>as a constructor parameter and call Create()when I need to use the component. In the context of the web application I am dealing with, it is very important that the UtilityService is bound to the web request (therefore it is registered with LifeStyle.PerWebRequest)
When I look at the “Potential Lifestyle Mismatch” container debug image, I get the message:
"IGenericFactory" Singleton * "TypedFactoryInterceptor" Transient This .
factory:
container.Register(Component.For<IGenericFactory<IUtilityService>>()
.AsFactory().LifestylePerWebRequest());
, , , Windsor factory -. , IUtilityService, singleton factory, factory . ( )
?
factory IUtilityService -?