Multiproject areas in ASP.Net MVC 3
Asked Answered
O

2

22

Does any one have any idea about multiproject area support in asp.net mvc 3? As it was degraded to future status in mvc 2. If it is still not included then should we look forward for ASP.Net MVC Portable Areas via MvcContrib. Can you share your expreriences?

What are the recommended way for managing a large application? I read about MEF. In what scenarios MEF is recommended?

Opulence answered 19/10, 2010 at 7:27 Comment(0)
T
15

I'm the development lead on ASP.NET MVC at Microsoft.

There are no plans to include multi-project areas in ASP.NET MVC 3. However, it's definitely an area that we plan to revisit in the future.

In the meantime MvcContrib's solutions are probably the best bet. The MVC Futures download still includes an old (and perhaps only semi-functional) version of the original multi-project areas feature. Because the full source code for it is also available, you might be able to construct a solution that is customized to your needs.

Tillage answered 19/10, 2010 at 17:18 Comment(2)
This is, in my humble opinion, the weakest part of ASP.NET MVC at the moment. I hope the MVC team will work on this as soon as possible. Being able to create a modular environment is definitively a must for us.Likewise
MVC4 timing could be a bit sooner but with enterprise LOB in limbo with Silverlight, you need to have the story solidified to switch to MVC4.... hopefully P&P can get involved with a silk like example!Wheeling
A
6

I need to have the same structure so I have figured out how to have areas as separate projects. There are no code changes needed, just a bit of configuration work you have to do.

I am going to create a blog entry on this but here are the basic steps.

Let's assume you have a single MVC application project and this will be your "shell" app.

  1. right click on the shell project and "Add Area...". Type in the area name. This will create an Areas folder with your area in it. (This is not 100% needed but you do need the "Areas" folder and you can steal the XXXXAreaRegistration class for your application.)

  2. Create a new MVC3 empty project in your solution to match your area. Move the XXXXAreaRegistration.cs file to the new project and adjust the namespace as applicable.

  3. Delete the folder under the areas folder that the template wizard added.

  4. Modify the web.config of the new project and take out the connection strings and the authentication, membership, profile, rolemanger sections. You don't really need the web.config but the razor intellisense doesn't work without it.

  5. Create a virtual directory in the "Areas" folder of the shell project with the name of your area as the alias and point it to your "area" project. You will need to use IIS or IIS Express for this. I use IIS. In IIS express you have to modify the config file. I think ScottGu had a blog entry on how to do this.

  6. Create a post-build event on your "area" project to copy the dll to the "shell" projects bin folder. My build event is: copy $(TargetDir)\$(TargetFileName) $(SolutionDir)\ShellProjectName\bin\$(TargetFileName)

  7. In the shell web.config add the "area" project into the System.Web/Assemblies section.

Instead of 6/7 you can just reference the "area" project with the "shell" project and it works just as well. But, then you have to deploy all the "area" dlls every time. I am probably going to do some type of probing code to add the "area" assemblies to the app domain at app start up using reflection or MEF.

You might also want to edit your routing and add the namespace filter to it in both the shell app and the area app. This way you don't have to worry about duplicate controller names conflicting between the sell app and the area apps.

That's about it. Once I get a formal blog entry posted up I will try to remember to add a link to it here.

I blogged how I am doing this at http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects if anyone is interested.

Accumulation answered 23/8, 2011 at 20:32 Comment(3)
Hmm looks interesting. Waiting to see your blog entry specially the MEF partOpulence
After further testing I have determined that no reference is needed to the area projects. Apparently the MVC code uses the BuildManager to get a list of assemblies. So, you don't need to do anything more than set up your "area" projects to output to the shell projects bin folder.Accumulation
I blogged how I am doing this at bob.archer.net/content/aspnet-mvc3-areas-separate-projects if anyone is interested.Accumulation

© 2022 - 2024 — McMap. All rights reserved.