I am using the TypeFactoryFacility with a generic factory to avoid having the container instantiate components until they are required. The generic factory looks like this:
public interface IGenericFactory<T> {
T Create();
void Release(T dummyComponent);
}
Later I use it in the following fashion:
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 (which is why it is registered with LifeStyle.PerWebRequest)
When I look at the containers debugger view "Potential lifestyle mismatches" I get a message:
Component 'IGenericFactory' with lifestyle Singleton* depends on 'TypedFactoryInterceptor' with lifestyle Transient This kind of dependency is usually not desired and may lead to various kinds of bugs.
If I register the generic factory:
container.Register(Component.For<IGenericFactory<IUtilityService>>()
.AsFactory().LifestylePerWebRequest());
Then the message goes away, but I wonder if I am losing out because now Windsor will create a factory for every web request. This will be cheaper than resolving the IUtilityService but it would be nice to only have to use a singleton factory as this factory does not have any dependencies. (that are created by me)
Is it an issue to register components as such? Will the factory will resolve the component IUtilityService per web request?