2013-01-15 31 views
1

我有問題,爲已經註冊的組件添加附加服務。 我有以下情況:如何爲已經註冊的組件添加附加服務

public class MyImplementation : BaseClass, IInterface 
{ 

} 

某處在我的應用程序的基礎架構(這是不是隨時更改),我的課是註冊於以下方式:

container.Register(Classes 
           .FromThisAssembly() 
           .BasedOn(typeof (BaseClass)) 
           .WithServiceBase()                  
           .LifestyleTransient()); 

我想什麼現在要做的是向MyImplementation組件添加額外的服務。我試着用下面的方法做它在我的安裝程序:

container.Register(Classes 
           .FromThisAssembly() 
           .BasedOn(typeof (IInterface)) 
           .WithServiceBase()                  
           .LifestyleTransient()); 

但試圖從容器解決IInterface當我得到錯誤說沒有對IInterface註冊的組件。

我的問題是,如果可以添加額外的服務已註冊的組件? 在此先感謝。 邁克

+0

它可以註冊使用'AllInterfaces(多種服務)' - 然而,在你的情況下,這可能意味着改變現有註冊。看到所有的接口文檔在這裏:http://docs.castleproject.org/Windsor.Registering-components-by-conventions.ashx –

+0

這是我的初步解決方案。然而,這將潛在地註冊組件與我不想要的接口,這對我來說並不好,但是我仍然沒有想出更好的解決方案。 – stachu

回答

0

如果你改變第二對準它會工作,我認爲:

container.Register(Classes 
          .FromThisAssembly() 
          .BasedOn(typeof (IInterface)) 
          .WithServiceAllInterfaces()                  
          .LifestyleTransient()); 
相關問題