【问题标题】:Where is the place for dependencies resolving using IoC within WPF app?在 WPF 应用程序中使用 IoC 解决依赖关系的位置在哪里?
【发布时间】:2013-10-07 05:43:48
【问题描述】:

我在 Mark Seemann 的“.NET 中的依赖注入”中读到,应该有一个地方(每个地方)必须调用 Register、Resolve 和 Release。现在,我正在尝试设置新 WPF 项目的环境。我们的团队决定使用 Caliburn.Micro 作为 MVVM 框架,使用 MEF 作为 IoC。 所以,我清楚地知道必须在哪里调用 Register,但是 Resolve 呢? 我也在书中读到,在 ASP.NET MVC 应用程序中有一个必须调用 Resolve 的地方:

override IController GetControllerInstance(RequestContext requestContext,
                                           Type controllerType) {
    return (IController)this.container.Resolve(controllerType);
}

但是调用应该驻留在 WPF 应用程序中的什么位置?此外,Caliburn 能否以某种方式帮助解决这个问题?

【问题讨论】:

  • 好吧,Bootstrapper.cs 中的 DisplayRootViewFor(Type viewModelType) 似乎就是为了这个目的。

标签: wpf mvvm ioc-container caliburn.micro


【解决方案1】:

但是调用应该驻留在 WPF 应用程序中的什么位置?此外,Caliburn 能否以某种方式帮助解决这个问题?

实际上,Caliburn.Micro 会为您处理这部分,因为当您从现有的 BootstrapperBase 或 Bootstrapper<TRootModel> 派生引导程序时,这些引导程序会调用一个名为 Start() 的方法,该方法会启动组成整个对象的一系列活动以TRootModel 或您所称的DisplayRootViewFor(Type viewModelType) 开头的应用程序图表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    • 2015-11-13
    • 2014-02-06
    • 2019-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多