如何解決基於服務接口我有一個接口。在那裏的傳遞給
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