0

Prism Commanding_Desktop QuickStart解决方案中,在 OrderModule 中,它定义了以下变量:

this.container.Resolve<OrdersEditorPresentationModel>()

但是这是在哪里注册的,以便可以从容器中“解析”出来?我在下面看到OrdersRepository的注册位置,但我在项目中找不到 OrdersEditorPresentationModel的注册位置。

订单模块.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)

我认为这可能是一些默认签名,但是 Prism 文档中的另一个示例,演示者构造函数具有不同的签名

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

1 回答 1

1

这种类型不必在任何地方声明,因为它是一个具体的实现。对于像 IMyInterface 这样不能自动实例化的接口,您必须事先注册一个具体的实现,以便当对象具有 IMyInterface 类型的依赖关系时,容器知道要实例化什么。

于 2009-07-20T17:42:12.753 回答