tjc59
tjc59

Reputation: 633

MVC .Net nested projects

We are in the process of a website redesign, and we'd like to transition over to MVC. It's a very large website, and our current situation is we have a root project, then we have sub-projects nested inside it for each of our departments. This way each department can be recompiled separately. Using virtual directories in IIS, we are also able to have a single Master Page in the root project, which all the other projects use (all our pages are currently ASPX). The downside to this virtual directory solution is that the root master page is not available to the sub-projects when debugging them. We'd like to switch to MVC, and hopefully MVC can solve this issue.

For the new website, I have created an MVC project that will serve as the root project. I have a shared layout all ready to go, but I'm having a couple of big problems:

  1. I can't figure out a workable way to create nested MVC projects for each department. I have tried a number of different ways, but I always end up with a 403 error. I was able to create Areas within the root project and this worked, but this will not allow us to recompile individual Areas, which is a must, as our site is simply too large.
  2. How to share the layout in the root with all the department projects (even during debugging) without relying on IIS virtual directories. I tried using Razor Generator, but it seems a little too complicated for me, and I could never get anything to work, or even figure out if it is capable of doing what I need.

Any advice would be much appreciated. MVC for .Net seems pretty useless for large sites if there is no way to separate sections into other projects that can be compiled individually.

Upvotes: 1

Views: 919

Answers (2)

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93494

To illustrate how this is done. Here's a snapshot of a test project I just threw together. The 403's you were getting were most likely because IIS is configured to no list the contents of folders, and those virtual directories had nothing in them.

The important thing here is that the Controllers and models are in a separate project. And your views are in your main project. It's much more difficult to try and package the views into your external projects. It can be done, but the thinking these days is that you would create nuget packages to deploy your areas to production (which means you end up with all your views together in production anyways).

This is a good first step for you. If you find this isn't enough, then you can look at other methods. But try to make this work for you first.

The other piece you need to do is change your AreaRegistration (which also stays in your main site, though you could figure out a way via Dependency Injection to make these work in the separate projects)

public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "Test_default",
            "Test/{controller}/{action}/{id}",
            // add controller = "yourcontroller" for default controller for area
            new { controller = "Some", action = "Index", id = UrlParameter.Optional },
            new [] { "YourExternalProjectNamespace.Controllers" } <-- This gets added
        );
    }

enter image description here

Upvotes: 1

Peter Gluck
Peter Gluck

Reputation: 8236

In our soultion, we have a separate project for the presentation layer (MVC web site) that relies on DLLs compiled in other projects for individual areas (disciplines) and core classes (e.g., core repositories, security classes, domain models).

The areas are designed to use base classes that then reference the core or specific classes defined in the other libraries. We make heavy use of interfaces and generics to boilerplate most of the basic functionality in the presentation layer, and then extend it where necessary.

Upvotes: 0

Related Questions