The same solution for a project or a new project in one solution - Asp.net MVC / Web Api?

I wonder which is better. I created a webapi project and am currently working on creating an api.

In the future I want to get the full asp.net mvc 4 website, which may also contain forms for inserting data into my database.

I'm not sure if I should

a) Create a new area in my web api project and create your website from there.

b) Store it in the same area and just create new controllers, etc. In the web api project.

c) add the new asp.net mvc 4 project to the web api solution project.

+4
source share
4 answers

Definitely two projects. In fact, I would recommend three projects:

  • MVC website
  • Class library for sharing your DAL / Service layers
  • Web interface

Your MVC website does not need to request your web API, which will simply make unnecessary HTTP delay. Both your MVC site and your web API are just “interfaces” to your class library. They will reference the class library and interact with the class library.

The web API is only necessary if you are trying to provide third-party access or you are interacting with a project in a different language. If all this is .NET, just open the DLLs and call it afternoon.

+3
source

C. Scott Allen recently wrote a brilliant post on the coexistence of ASP.NET MVC and WebAPI, which covers the most common scenarios and when it is suitable for using WebAPI with MVC or when you just need to use MVC.

I would use this because your guide selects the solution that best suits your current needs. My advice is to keep it simple, and if your requirements are simple, then there is no reason not to keep WebAPI and MVC in the same project - it works fine. As your requirements change, you can always divide them into different projects or solutions, but by then you will definitely understand why you are doing this.

http://odetocode.com/blogs/scott/archive/2013/07/01/on-the-coexistence-of-asp-net-mvc-and-webapi.aspx

+2
source

absolutely,

follow the link http://efmvc.codeplex.com/

which is the best architecture for developing large applications

can this help you ...

another NEST level MVC BEST architecture

MVC ---------> WEB API (services) ------> here BL | DL (ORM) | DB)

which you create in one solution and create an application ...

0
source

Separate projects for the web api and web interface will help separate things, but this causes duplication. We went so recently and it works well, but it caused a few problems.

Arguments for having one project:

  • Since we don’t have a domain name yet, we have our API on port 8080. We could use directory binding to make the API accessible from a subdirectory of the web interface, but we were only concerned about producing absolute path resolution errors.

  • Many settings are shared between two projects, so we must copy them in both web.config files.

Arguments for several projects:

  • They are easier to update, as they can have different dependencies, and they can be created completely independently. For example, in our API project, several later versions of some dependencies are used.

  • This forces you to extract all your business logic into a separate library and simplify the idea of ​​all projects as separate subsystems.

  • It’s easier to configure the web interface on a separate computer if the load is too heavy. This bothers us, but it may not be your business.

If I had to make this decision again, I probably would not have to deal with individual projects if the system were not extremely complex and I need an additional structure. An argument can be made for both options, but I think the deployment headache that it brings is not worth it.

0
source

Source: https://habr.com/ru/post/1479390/


All Articles