问题描述
我是全新的国际奥委会,因此一直在之后的和的
I am brand new to IoC and thus have been following the examples provided by Jeffery Palermo in his posts at http://jeffreypalermo.com/blog/the-onion-architecture-part-1/ and in his book hosted here https://github.com/jeffreypalermo/mvc2inaction/tree/master/manuscript/Chapter23
最重要的是要注意的是我不是使用预轧IoC容器,主要是因为我想了解所有运动部件。
Most important to note is that I am not using a pre-rolled IoC container, mostly because I want to understand all the moving parts.
不过,我创建一个Windows服务,而不是一个ASP .NET MVC Web应用程序,所以我有点陷入泥淖的启动部分。具体而言,在web.config中,他注册了一个IHttpModule的实现里面的基础设施项目的启动模块,然后使用一个生成后事件所需的dll文件复制到网站目录来解决其在web项目本身的直接依赖。
However, I am creating a windows service rather than an ASP.NET MVC webapp so I am little bogged down on the startup portion. Specifically, in the web.config he registers an IHttpModule implementation INSIDE the infrastructure project as the startup module and then uses a post-build event to copy the necessary dlls into the website directory to get around having a direct dependency in the web project itself.
我不认为我有一个真正的Windows服务,这种类型的奢侈品,让我怎么实现类似的东西,我应该有依赖性小的启动项目到基础设施和核心两种,或者是有另一种方法来绕过Windows服务的编译时间限制吗?
I don't think I have this type of luxury in a true windows service, so how do I achieve something similar, should I have a small startup project which has dependencies to both the Infrastructure and Core, or is there another method to get around the compile-time restrictions of the windows service?
先谢谢了。
推荐答案
根据对这个问题(C#)我假设你通过的。如果是这样,OnStart方法将是您的构成根 - 这是您撰写应用程序的对象图。您撰写对象图后,组成了和合成对象图接管。
Based on the tags of this question (c#) I'm assuming that you'll implement the Windows Service by deriving from ServiceBase. If so, the OnStart method will be your Composition Root - this is where you compose the application's object graph. After you've composed the object graph, composition is over and the composed object graph takes over.
在调用OnStop可以再次退役的对象图。
In OnStop you can decommission the object graph again.
有什么从实施单独的程序集解析的对象图的各个组成部分阻止你。这就是我会做。
There's nothing stopping you from implementing the various components of the resolved object graph in separate assemblies. That's what I would do.
这篇关于手动Windows服务实现的IoC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!