在将 Onion Architecture 与Windows Forms UI 层相结合时,我遇到了障碍。问题是我的IoC配置方法永远不会被命中。IoC 设置发生在依赖解析程序集中:
Project.Core
Project.Infrastructure
Project.UI <- Startup project
Project.DependencyResolution <- IoC configuration
而且我希望我的 UI 层除了Project.Core
.
在我使用此架构的 Web 项目中,我使用了 WebActivatorEx 和 OutputTo 来引导我的 IoC。因为我很熟悉,所以我决定在这里使用相同的,但它的行为不像预期的那样。我不确定我是问题还是 Windows 窗体是问题所以这是我的设置:
在 Project.DependencyResolution 中:
[assembly: WebActivatorEx.PreApplicationStartMethod(
typeof (IocConfig), "RegisterDependencies")]
public class IocConfig
{
public static void RegisterDependencies() {
// this is never executed
}
}
OutputTo 的 OutputTargets.txt:
..\Project.UI\bin
在 Project.UI 中:
static class Program
{
static void Main() {
WebActivatorEx.ActivationManager.RunPreStartMethods();
Application.Run(...);
}
}
OutputToDependencyResolution's
将 DLL 文件正确复制到Ui's
bin,但从IocConfig.RegisterDependencies
不运行。
那么如何从它自己的程序集中设置 IoC,其中 Windows 窗体项目是启动项目?