Im very unsure how i should approach this as im new to the Unity Container.
Heres a factory i have:
class DataCopierFactory : IDataCopierFactory
{
private readonly IUnityContainer _container;
//not mad on binding the factory to the container, but feck it
public DataCopierFactory(IUnityContainer container)
{
_container = container;
}
//return a data copier that will transfer data from any DB to any other DB
public IDataCopier createDataCopier(int i)
{
switch(i)
{
case 1:
return new ScheduleDataCopier(new LTEEFContext()); //somehow resolve the LTEEFContext..
//case 2:
//
default:
throw new InvalidOperationException("Parameter -t=" + i + " does not exist");
}
}
}
When i call the createDataCopier method and pass in some enum, I want to use the Unity container to resolve my DB Object Context of the various types of IDataCopiers.
How do i do this?
Should i do it in the class that calls the factory? or inject the unitycontainer and resolve the different DB Object Contexts at that point.
Each Implementation of the IDatacopier has a IDBContext taken as a constructor, I want to basically inject this, but allow me to change the Context for different implementations of the Datacopier.
Hopefully this makes sense... :) Thanks in advance Neil