Home > front end >  MVC-based plugin in ASP.NET Core?
MVC-based plugin in ASP.NET Core?

Time:07-12

for several years I'm developing applications for Windows using C#. For web development I used PHP. Now I would like to start developing web applications using ASP.NET. My first Hello World project is running and so I'm planing my first productive application. This application will provide several "small" independant applications which (in the first step) will not interact with each others. The only thing that should be provided from the base application is the user management (login, roles, rights, ...).

Now my question is it is possible to develop these smaller applications as libraries (e.g. DLL) and load them into the "main" application? This means having the model, the view and the controller all together in the library. In the web i haven't found an example that contains all these parts in a library. Maybe I'm just missing the right key words.

If it is possible my next question is this even makes sense to do it in such a way. I'm happy about all of your help.

Thank you very much.

CodePudding user response:

You can create class Library projects and refer those dlls into your main project. Refer this link: https://docs.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio?pivots=dotnet-6-0

CodePudding user response:

REFERENCES

I found out that this post has some similiarities with this one.

Check this link for extra documentation: https://docs.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio?pivots=dotnet-6-0

Area Documentation: https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-6.0

MVC Modules as Libraries

It makes sense to separate your modules via DLLs. This is odd when you have several contents already developed in your website and you don't want to redeploy the whole business when something is changed.

However, there is a simpler way to separate your modules, offering an even better understanding of what's going on in your website while you debug/develop: Areas.

MVC Areas ASP.NET Core are a complex subject that i would suggest you to research on your own. Some cons are:

  • Helps you separating the website contents.
  • It is easier to map routings.
  • It is better when you have to develop middleware.
  • Way easier to debug, because everything is in the same project.
  • ...

Final Toughts

Libraries are useful in a productive scenario, because stopping a service can become expensive and hurt your business.

CodePudding user response:

ASP.NET Core works just fine in MVC format, that's how I've used it. A lot of what I learned via working with MVC in Java's Sprint Boot applied for ASP.NET

So for example:

  • Your DTO/model layer is a class library, who's dll will be referenced throughout
  • Your DAO layer will be another class library, which can contain interfaces and implementations. Will be referenced by Service layer and unit tests
  • Service layer, another class library, will be referenced by controller layer and unit tests
  • Your unit testing layer will test the code from the DAO and Service layers
  • Controller layer will manage the interactions between front end and back end. Backend objects get passed as models to the front end for Razor to use in templating
  • In ASP.NET your view layer is housed in the pre-made ~/Views directory, with its javascript resources housed in directories like ~/Content, ~/Fonts, etc.

This MS tutorial landing page may be a good place to start.

But you don't need a plugin for it, you can use dotnet new mvc SolutionNameHere from the cmd line with more of the necessary flags you want to generate it in the basic MVC format. From there, set up your model, dao, service, and testing layers, make the necessary references throughout, and begin developing. The front end layer and controller layer have their basic setup done for you already

  • Related