I came across this piece of code:
public class SomeServiceFactory : ISomeServiceFactory
{
private IUnityContainer container;
public SomeServiceFactory(IUnityContainer unityContainer)
{
this.container = unityContainer;
}
public virtual ISomeService GetSomeService()
{
return this.container.Resolve<ISomeService>();
}
}
I'm trying to understand how this pattern is more useful then simply having the consumer of this factory simply be injected with ISomeService
directly? Thus, become a consumer of the service itself, rather than the factory. What does this additional layer of indirection achieve, as implemented here?
I understand that if the creation of ISomeService
needed more intricate logic, not achievable by container.Resolve
, then definitely a factory would have been required.