简体   繁体   English

Windows Service with Onion体系结构

[英]Windows Service with Onion Architecture

All the onion architecture examples I've seen are within the context of ASP.NET MVC apps. 我见过的所有洋葱体系结构示例都在ASP.NET MVC应用程序的上下文中。 They tend to avoid a direct reference between the UI and the service implementations (infrastructure) by putting IoC setup in the infrastructure DLL and using some magic (HttpModule or WebActivator) to make IIS execute that setup code at the right time. 他们倾向于通过将IoC安装程序放入基础结构DLL中并使用一些魔术(HttpModule或WebActivator)使IIS在正确的时间执行该安装程序代码,从而避免在UI与服务实现(基础结构)之间直接引用。

In my case, I'm working on a Windows (TopShelf) Service, and struggling with how to keep the service control project completely decoupled from the infrastructure project. 就我而言,我正在研究Windows(TopShelf)服务,并在努力使服务控制项目与基础结构项目完全脱钩。 There is no execution pipeline to hook into like in an IIS web app. 没有执行管道可以像IIS Web应用程序一样挂接到。

The best I can think of is to have the service project scan DLLs for IoC registry/module classes, but that still doesn't seem as clean. 我能想到的最好的方法是让服务项目扫描IoC注册表/模块类的DLL,但这似乎还不干净。

Any ideas? 有任何想法吗?

A Windows Service is by definition not a UI, so I'm not sure what this would achieve. Windows Service从定义上来说不是UI,所以我不确定这将实现什么。

All the TopShelf project needs is a reference to the actual service class: your infrastructure project does not need a reference to TopShelf, as shown in the documentation . TopShelf项目所需的全部是对实际服务类的引用:您的基础结构项目不需要对TopShelf的引用,如文档中所示

If you don't have a reference to the infrastructure service from the TopShelf project, then configuring your service is going to be ugly. 如果您没有TopShelf项目中对基础结构服务的引用,则配置服务将很丑陋。

You will need to use an ObjectFactory or ServiceResolver or some such to construct the service using IoC, but this will be the composition root anyway. 您将需要使用ObjectFactory或ServiceResolver或类似工具来使用IoC构造服务,但是无论如何,这将是组合的根。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM