I've just started the project and I have this sort of parts in my solution

  • MyApp.Web MVC Web Application
  • MyApp.Data Class Library
  • MyApp.Domain Class Library
  • MyApp.Service Class Library
  • MyApp.Utility Class Library

So I wanted to have webapi in my application, and my question is where should I put the webapi codes. in separate part like MyApp.API or in Data or Service part.

thank you.

有帮助吗?

解决方案

I prefer this structure:

  1. MyApp.Web // UI
  2. MyApp.Core // Context
  3. MyApp.Domain
  4. MyApp.Service
  5. MyApp.Api // WebAPI
  6. MyApp.Utility // it's depended on your case !, I didn't use this layer so far.

If you use DI in your project, you should use Custom Controller Factory, so I prefer WebAPI as separated layer and create specific Custom Controller Factory, instead of something global that covering MVC Controller too.

其他提示

You should absolute not put it in the data layer. That would be weird because none of the dependencies you need for web api are, and should not be, present in the data layer.

It is fairly common to have mixed mvc and web api into the same assembly and it has the advantage that deployment is easier.

If you want a more clean approach. Clean in the sense that we keep the number of unrelated dependencies to a minimum in each project, you can introduce a seperate assembly with web api only. This will sligtly minimize the risk of running into dll hell but complicate deployment slightly.

许可以下: CC-BY-SA归因
scroll top