2009-07-20 71 views
0

棱鏡Commanding_Desktop快速啓動溶液,在OrderModule,它定義了一個變量爲以下:在棱鏡中註冊哪些類型?

this.container.Resolve<OrdersEditorPresentationModel>() 

其中這個被註冊,以便它可以被「解決」從容器中?我在下面看到OrdersRepository正在註冊,但我找不到在哪裏項目OrdersEditorPresentationModel正在註冊。

OrderModule.cs:

public void Initialize() 
{ 
    this.container.RegisterType<IOrdersRepository, OrdersRepository>(new ContainerControlledLifetimeManager()); 

    OrdersEditorPresentationModel presentationModel = this.container.Resolve<OrdersEditorPresentationModel>(); 

    ... 
} 

OrdersEditorPresentationModel.cs:

public class OrdersEditorPresentationModel : INotifyPropertyChanged 
{ 
    ... 

    public OrdersEditorPresentationModel(OrdersEditorView view, IOrdersRepository ordersRepository, OrdersCommandProxy commandProxy) 
    { 
     this.ordersRepository = ordersRepository; 
     this.commandProxy = commandProxy; 
     this.Orders = new ObservableCollection<OrderPresentationModel>(); 
     this.PopulateOrders(); 

     this.View = view; 
     view.Model = this; 
    } 

    ... 

在類型的構造上述被解決具有特定的簽名,但其中是這個簽名被定義爲:

public OrdersEditorPresentationModel(OrdersEditorView view, 
        IOrdersRepository ordersRepository, 
        OrdersCommandProxy commandProxy) 

我想這可能是一些默認的簽名,但棱鏡文檔中的另一個例子,演示構造有不同的簽名

public EmployeesPresenter(IEmployeesView view, 
     IEmployeesListPresenter listPresenter, 
     IEmployeesController employeeController) 

回答

1

這種類型沒有在任何地方申報因爲它是一個具體的實現。對於像IMyInterface這樣不能自動實例化的接口,你必須事先註冊一個具體的實現,以便當對象具有IMyInterface類型的壓縮時,Container知道要實例化什麼。