如何解决基于服务接口我有一个接口。在那里的传递给
public interface ISomeInterface {...}
和两个实现(SomeImpl1和SomeImpl2):
public class SomeImpl1 : ISomeInterface {...}
public class SomeImpl2 : ISomeInterface {...}
我也有两个服务在那里我(通过构造器)注入ISomeInterface:
public class Service1 : IService1
{
public Service1(ISomeInterface someInterface)
{
}
...
}
和
public class Service2 : IService2
{
public Service2(ISomeInterface someInterface)
{
}
...
}
我使用AUT ofac作为我的IoC工具。 这个问题。如何配置Autofac注册这样SomeImpl1将自动注入到服务1,和SomeImpl2将自动注入到服务2。
谢谢!
感谢您的答复。它工作正常。但是我的SomeImpl1和SomeImpl2依赖于很多其他服务。我不想在注册时指定所有人。有没有办法在注册期间不创建实例来实现它:new SomeImpl1()? – 2011-06-07 12:02:47
我的意思是:builder.RegisterType().As ()。([如何在Service1的第一个参数中指定“impl1”?]); –
2011-06-07 12:05:11
我已经更新了答案,显示了如何使用'RegisterType'获得同样的结果。 – bentayloruk 2011-06-07 13:11:00