I have an interface like the one below that I insert into the units container.
public interface IMyInstanceFactory { IEnumerable<IMyInstance> GetAll(); }
All IMyInstance known before launch, that is, they can be configured in the boot block and can be extracted from one. My specific implementation for IMyInstanceFactory as follows:
public class MyInstanceFactory:IMyInstanceFactory { IUnityContainer _container; public MyInstanceFactory(IUnityContainer container) { _container = container; } public IEnumerable<IMyInstance> GetAll() { return _container.ResolveAll<IMyInstance>(); } }
.. and in my bootstrapper I do something like this:
container.RegisterType<IMyInstance,MyInstance1>; container.RegisterType<IMyInstance,MyInstance2>; container.RegisterType<IMyInstance,MyInstance3>; container.RegisterType<IMyInstanceFactory,MyInstanceFactory>;
It perfectly eliminates everything. However, I donβt want to depend on the container itself or implement IMyInstanceFactory just for that, is there a way I can install without implementing IMyInstanceFactory ? Does unity provide a means to this?
Something like that ..
container.RegisterType<IMyInstanceFactory,factory=>factory.GetAll()>().IsResolvedBy(unity.ResolveAll<IMyInstance>);
I know a castle can do this, can Unity do something like this?
source share