Sample Code for Creating ASP.NET MVC
Table of Contents
Introduction
AddMVCModuleDynamic — a very simple version of how to make ASP.NET MVC modular.
Overview
This MVC web application template demonstrates how you can dynamically add MVC projects to your main web MVC application.
With this example, you can have distributed teams where one team works on MVC Project 1 along with all the backend domain and database access, while another team works on MVC Project 2 with different backend projects.
When you build and deploy, it is very simple. You just build the solution and all the MVC projects will go to the main web MVC project. When you deploy the main web project, the application will grab the files and deploy them too.
Tools
Visual Studio 2013, C#, MVC
Key Points
-
Main MVC project has no reference to other MVC projects
-
*.pubxml is the key file that needs to be edited when publishing
-
Each module MVC project needs to add the following command after build:
-
xcopy /E /Y /D "$(ProjectDir)Views" "$(SolutionDir)MainWeb\Views"
-
xcopy /E /Y /D "$(ProjectDir)Scripts" "$(SolutionDir)MainWeb\Scripts"
-
xcopy /E /Y /D "$(ProjectDir)Content" "$(SolutionDir)MainWeb\Content"
-
Things to Watch Out For
-
Need to be careful with the DLL versions between projects.
-
Have not tested whether the build will bring all module MVC project's referenced DLLs.
-
Not supported for DI or IoC modules yet.
Conclusion
This is a simple approach to making ASP.NET MVC modular. By using xcopy commands and publish profiles, you can split your application into multiple MVC projects that are merged at build time. Check the GitHub repo for the full source code.