简体   繁体   中英

use owin to self host web api

I'm self hosting web api using owin on client-server application based on MVC architecture. I see a lot of code examples that shows that the Startup class with the configuration, and the Program class with the Main method that start the owin self host "using (WebApp.Start(url: baseAddress))" - are at the same project. Should I desperate owin self host to one project so the WebApp.Start will be in one project, and web api with Startup claas to another one, with all the controllers and so?

The common answer is that it depends. Usually self host applications is very simple to provide some simple functionality. In that case since both parts are simple there is no need to separate them (host code and Asp.Net Mvc ) and they can be placed in one project as an application layer. But if you are trying to add some complexity to host code (eg some warm up of Asp.Net Mvc app), then may be you should split your host code and Asp.Net Mvc app code in to two projects.

Found that it might be good idea inspired by separation of concerns: the self host should not know about the server and the opposite. Owin and web api have different job so they need to be separated.

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