Multiproject areas in ASP.Net MVC 3

末鹿安然 提交于 2019-11-27 10:53:43

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3966124/multiproject-areas-in-asp-net-mvc-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!