简体   繁体   中英

Windows Service with Onion Architecture

All the onion architecture examples I've seen are within the context of ASP.NET MVC apps. 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.

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. There is no execution pipeline to hook into like in an IIS web app.

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.

Any ideas?

A Windows Service is by definition not a UI, so I'm not sure what this would achieve.

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 .

If you don't have a reference to the infrastructure service from the TopShelf project, then configuring your service is going to be ugly.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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