2010-01-28 64 views
0

好吧,我想設置一個屬性,我正在用SM註冊一個類型。StructureMap 202 - 爲什麼?

下面是我的一個組件的註冊表中的代碼。這個 註冊表正在從控制檯應用程序配置期間添加。 當我嘗試訪問實例 AutoMandatoryEndorsementAggregator對象的EndorsementSpecs財產,我得到的202有什麼 有趣的是,我可以打電話給 GetAllInstances>()從我 控制檯應用程序,它解決了就好了。有沒有關於 訪問從OnCreation內導致202? I 可以在WhatDoIHave()中看到我所期望的一切。我也試過了一個TypeInterceptor,結果相同。

//register all open generics 
cfg.ConnectImplementationsToTypesClosing(typeof 
(MandatoryEndorsementSpecBase<>)); 

ForSingletonOf<IMandatoryEndorsementAggregator<AutoPolicy>>() 
        .Use<AutoMandatoryEndorsementAggregator>() 
        .OnCreation((context, x) => 
        { 

         var specs = 
context.GetAllInstances<MandatoryEndorsementSpecBase<AutoPolicy>>(); 
         x.EndorsementSpecs = specs; 
        }) 
        ; 

回答

0

對不起偏轉你真正的問題,但你只是想MandatoryEndorsementSpecBase的所有實例注入AutoMandatoryEndorsementAggregatory? 如果是這樣,你可能只是把它作爲一個構造函數參數,以便它們都被自動注入。

public AutoMandatoryEndorsementAggregatory(MandatoryEndorsementSpecBase<AutoPolicy>[] endorsementSpecs){ 
    EndorsementSpecs = endorsementSpecs; 
} 
+0

其實,這是我落得這樣做,它的作品,因爲我知道它會,但也有情況下,做這樣的事情是有意義的(否則此功能將不存在),因此在某些時候我我們可能不得不處理弄清楚發生了什麼問題。 – 2010-01-31 18:29:11