2012-03-12 37 views
3

我有一個MVC 3應用程序,它具有一些核心功能(最重要的是自動化),但主要用作不同區域或模塊的入口。我想組織thit到不同的模塊,只需稍作修改,也可以部署爲他們自己的網站。如何將MVC項目分離到幾個較小的MVC項目

該項目包括一個論壇,博客引擎,用戶之間的消息+ 4-5即將到來的模塊。

我看着ScottGu的約MVC 2博客,發現的東西,似乎完美:

enter image description here

根據OG什麼客戶需要我只想給他們,他們可以使用完全相同的模塊。從維護視角來看,更容易處理和更新每個項目中的參考裝配,並且只需對其服務器上具有該特定模塊的客戶進行全面更新。

但是在MVC 3中沒有明顯的方式使用區域這種方式,你知道怎麼做嗎?

狀態 我會盡量MVCContrib便攜式領域添加到現有的解決方案,並轉換我的領域未變,並且將回發的結果。如果有效,我會將其標記爲可接受的解決方案。

+1

你吃過看看便攜領域(MVCContrib的一部分) - http://mvccontrib.codeplex.com/文檔?他們會適合你在尋找的東西 – 2012-03-12 14:00:48

+0

@Russ是的,簡單地說,但我根據ScottGu的帖子推測,這是在沒有另一個框架的情況下完成的。當MVC 4到來時,我可能會開發新的模塊,但是Portable Area可能不支持我所知道的所有模塊,並且因爲這一點而陷入困境有點令人沮喪。 Mayby我過分謹慎,這不會是一個問題。 – cfs 2012-03-12 14:19:46

+0

爲什麼你不能在MVC 3中遵循ScottGu的方法? – jrummell 2012-03-12 17:03:25

回答

3
+0

謝謝。正如上面提到的,我已經簡要了解了它,但有點急於讓它成爲mye應用程序的核心部分,因爲它有更新。但如果這是解決我的問題的可靠方式,並且有很多使用它,我想我只是太懷疑。儘管應該是MVC的固有部分,但根據Scott Gu的博客,似乎至少是該計劃。 – cfs 2012-03-12 14:25:44

+0

有一個問題,我似乎沒有找到關於這個接近的答案。將此項添加到現有解決方案並將兩個現有區域遷移到便攜式區域是否存在問題? – cfs 2012-03-12 14:41:25

+0

@cfs - 找出答案的唯一方法就是試試! – 2012-03-12 17:04:02

1

這是可能的MVC3: 來源: http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects

 
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.) 

Create a new MVC3 empty project in your solution to match your area. Move the XXXXAreaRegistration.cs file from the shell mvc project to the new project and adjust the namespace as applicable. (Or you can manually create an area registration class, it's a pretty simple class. Just use the Add area template generated one as an example.) 

Edit the routes in the AreaRegistration folder as needed. 

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

Modify the web.config of the new project and take out the connection strings and the authentication, membership, profile, rolemanger sections. You will not need to deploy this web.config but the razor intellisense doesn't work without it during dev time. 

Delete the global.asax file from the area's project or you will get extra default routes. 

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. For IIS Express you can use the appcmd.exe in the IIS Express folder or you can edit the applciationhost.config file. 
+1

感謝Adam,但這表明我必須對每個部署的IIS配置特定的配置並設置虛擬目錄?這不是最大的問題,但理想情況下我想避免這個問題。 – cfs 2012-03-12 14:22:53

+0

鏈接到的URL不再可用。我建議從[web.archive.org(https://web.archive.org/web/20140411193340/http://bob.archer.net/content/aspnet-mvc3-改變到最後已知的緩存副本區,獨立的項目)。 – 2017-01-09 13:09:05