When Controller1 is being created, I want that IService will be mapped to ConcreteService1 and IPageService to ConcretePageService1
And when Controller2 is created, I want that IService will be mapped to ConcreteService2 and IPageService to ConcretePageService2
How I can initialize ObjectFactory so that the above will work?
Mean while I initialezed ObjectFactory this way:
ObjectFactory.Initialize(x =>
{
x.For<IService>().Use<ConcreteService1>();
x.For<IPageService>().Use<ConcretePageService1>();
});
But this ALWAYS maps ConcreteService1 to IService and ConcretePageService1 to IPageService regardless of controller type
public class Controller1 : Controller
{
public Controller1(IService service, IPageService pageService)
{
}
}
public class Controller2 : Controller
{
public Controller2(IService service, IPageService pageService)
{
}
}
public interface IService
{
}
public class ConcreteService1:IService
{
}
public class ConcreteService2:IService
{
}
public interface IPageService
{
}
public class ConcretePageService1:IPageService
{
}
public class ConcretePageService2:IPageService
{
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…