2013-05-02 132 views

回答

1

通過Bootstrapper.BuildUp()是 - 只需撥打container.BuildUp(instance)

在你的引導程序:

SimpleContainer _container; 

protected override void Configure() 
{ 
    _container = new SimpleContainer(); 

    // Register stuff: 
    _container.RegisterSingleton(typeof(IWindowManager), null, typeof(WindowManager)); 

    base.Configure(); 
} 

// Property inject: 
protected override void BuildUp(object instance) 
{ 
    _container.BuildUp(instance); 
} 

呼籲在代碼中IoC.BuildUp將通過Bootstrapper.BuildUp方法

0

是的,它支持通過任何東西。

物業注射

屬性注入提供了中注入服務的依賴容器之外創建一個實體的能力。當一個實體被傳入BuildUp方法時,它的屬性將被檢查,並且任何可用的匹配服務都將使用與上面相同的遞歸邏輯來注入。

... 
     var shellViewModel = new ShellViewModel(); 
     _container.BuildUp(shellViewModel); 
    } 
} 


public class ShellViewModel { 
    public IEventAggregator EventAggregator { get; set; } 
} 

在大多數情況下,構造函數注入是最好的選擇,因爲它使服務需求明確的,但是物業注入有許多用例。注意屬性注入僅適用於接口類型,這一點很重要。

來源:Caliburn.Micro Documentation