2017-07-31 35 views
1

我已經在App主機中註冊了IOC(func)的以下類型。類&下面給出的接口位於單獨的類庫中。此類庫包含WCF服務引用。服務棧如何動態註冊來自不同程序集的類型

private void RegisteTyeps(Container container) 
     { 

      //Register Mapper 
      container.Register<IMapper>(c => _mapperConfiguration.CreateMapper()); 


      container.RegisterAutoWiredAs<AppointmentHandler, IAppointmentHandler>().ReusedWithin(ReuseScope.Container); 
      container.RegisterAutoWiredAs<CalendarHandler, ICalendarHandler>().ReusedWithin(ReuseScope.Container); 
      container.RegisterAutoWiredAs<SettingHandler, ISettingHandler>().ReusedWithin(ReuseScope.Container); 

     } 

我想添加一些更多的服務引用(比彼此略有不同),併產生proxies.Thus我加入與相應的服務多一些類庫引用。每個類庫中包含「相同」的界面和CLASSE正如剛纔提到的 。

我想動態加載/切換基於請求頭或類的東西,以便我只能使用具有相應服務參考&代理的特定庫。

我怎樣才能達到這與服務堆棧。任何一個有任何想法?

回答

1

您只能在Funq中註冊一個類型或接口的依賴項。如果要執行多個註冊,你要麼需要註冊一個工廠類型,e.g:

container.Register(c => new AppointmentHandlers(
    new AppointmentHandler1(), 
    new AppointmentHandler2()); 

然後解決它:

public AppointmentHandlers AppointmentHandlers { get; set; } 

public object Any(MyRequest request) 
{ 
    var dep = AppointmentHandlers.AppointmentHandler1(); 
} 

否則,你需要register them with different interfaces or use a named registration

+0

酷!我沒有考慮工廠,它解決了我的問題。謝謝! – Thabo

相關問題