Sharing features of an MVC application

I have a built-in application and an application in ASP.NET MVC that started as a tool for learning technology. However, the application (and my knowledge of MVC) has advanced, and I would like to use parts of the functionality that I created in other applications. For example, I would have 2 websites that would like to use the same news management methods (CRUD) and controller methods, but with their own unique views. I suppose my questions are: 1. Is this against the principles of MVC? 2. What is the best way to achieve this? 3. Is there a “best practice” way to reuse my existing features?

Thanks in advance for any answers.

+4
source share
4 answers

Depending on your exact requirements, I would recommend that you take a look at the Rob Ashton series on multi-tenancy in ASP.Net MVC , as well as some of the portable areas of MVC Contrib .

+1
source

You can configure the Visual Studio solution in which you will have a common class library project containing models, controllers and data access, and two web applications containing only views and CSS of two sites that link to the same controllers and models.

0
source

I hope that most of your logic is already separate, but you can also bring your controllers to a separate assembly, I suppose:

http://dotnetslackers.com/articles/aspnet/storing-asp-net-mvc-controllers-views-in-separate-assemblies.aspx

0
source

Reuse is truly a central part of the MVC concept. Very often, MVC production sites have a separate assembly (or assemblies) for the model. This is somewhat less common (but still done) in order to do the same for controllers. The S # arcade architecture project (for example) uses a separate assembly for everything, leaving only the views, content and global.asax in the web assembly. All is well.

Another thing you can consider is using areas that are similar to mini-MVC applications that you can use in your “main” application. This is a great way to pack reusable items as you describe.

Floor

0
source

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


All Articles