2010-11-29 17 views
0

對不起,我的小問題打擾社區,但我只是卡住了!WCF服務連線自動配置問題

在我們進入細節之前,這裏是我的服務模塊的容器設置!

public class ServiceModule : Module 
    { 
     protected override void Load(ContainerBuilder builder) 
     { 
      base.Load(builder); 

      builder.Register(c => new ContextService(c.Resolve<IContextDataProvider>(), 
                c.ResolveNamed<IExceptionShield>("SRV_HOST_SHIELD"), 
                c.Resolve<IMonitoring>())) 
       .As<IContextService>(); 

      builder.Register(c => new ExceptionShield(
       c.ResolveNamed<IShieldConfiguration>("SRV_SHIELD_CONFIG"))) 
       .Named<IExceptionShield>("SRV_HOST_SHIELD"); 

      builder.Register(c => new ServiceExceptionShieldConfiguration()).Named<IShieldConfiguration>("SRV_SHIELD_CONFIG"); 

      builder.RegisterType<ContextService>().Named<object>("Service.ContextService"); 
     } 
    } 

,我一直hawing的問題是,該服務的構造函數的第二個參數不能解決

我已經嘗試了所有,對我來說,已知,排列包括只是簡單地初始化參數,沒有容器的分辨率。但所有目的都在同一個例外:

None of the constructors found with 'Public binding flags' on type 'Service.ContextService' can be invoked with the available services and parameters: 
Cannot resolve parameter 'Common.ExceptionShield.IExceptionShield exceptionShield' of constructor 'Void .ctor(IContextDataProvider, Common.ExceptionShield.IExceptionShield, Common.Monitoring.IMonitoring)'. 

我必須在這裏失去一些至關重要的東西。如果你看到我的錯誤,那麼請告訴我:)

回答

2

發現問題。這是我忽略的一件小事。

Autofac只接受類型的最後一個定義。而且,因爲我重新登記了最後一個定義所用的類型。

這只是問題的一部分。另一部分(生成有趣的異常消息的部分)是RegisterType()嘗試自動裝入類型的事實。並且因爲所有對象都可以通過它們的類型找到,除了名爲的異常屏蔽

工作配置如下所示:

public class ServiceModule : Module 
    { 
     protected override void Load(ContainerBuilder builder) 
     { 
      base.Load(builder); 

      builder.Register(c => new ContextService(c.Resolve<IContextDataProvider>(), 
                c.ResolveNamed<IExceptionShield>("SRV_HOST_SHIELD"), 
                c.Resolve<IMonitoring>())) 
       .Named<object>("Service.ContextService"); 

      builder.Register(c => new ExceptionShield(
       c.ResolveNamed<IShieldConfiguration>("SRV_SHIELD_CONFIG"))) 
       .Named<IExceptionShield>("SRV_HOST_SHIELD"); 

      builder.Register(c => new ServiceExceptionShieldConfiguration()).Named<IShieldConfiguration>("SRV_SHIELD_CONFIG"); 
     } 
    } 

我花了幾個小時容易犯的錯誤要弄清楚。希望這有助於其他一些失去靈魂。