1

What I'm Doing Now

As it is now, every time I have a new project I need to work on (all of these projects use a pretty generalized base of functionality, but each have their custom functionality, quirks, etc.), I have to just copy the base project, and then modify the copied base project, to add the custom functionality.

The Idea

(I'm using ASP.NET MVC4, with Visual Studio 2012)
Basically, I'd like to have a "Base Project":

Base Project
-Controllers
-Models
-Views

Custom Project
-Controllers
-Models
-Views

that serves as the base for my MVC projects. Then, when I go to create a new project (spun off of the base project), I'd include the base project as a subproject to the solution, and in my new project, only have to write controllers/models/views that are different from the base (I'd like to just override those, or something similar).

This way, when I change the base project, the base projects of all of my different custom projects would be updated as well, this way I could update/bugfix/etc the base project, and not have to manually update each custom project to include this new base functionality.

The Problem

I understand that what I want is a little weird for MVC to handle, but I think I could get the whole routing engine to work the way I want, but I was just wondering if there were any solutions for this, that are a bit easier to implement. I feel like this is a fairly normal thing to want to do. Or am I thinking about the whole problem wrong?

What I've Tried

So far, I've created a base project, and a custom project, and I can get base functionality to appear in the custom project, if no Action is present in the custom controller, but the base project uses the custom project's View for that Action, whereas I need the base project to use it's own Action and View if they don't exist in the custom project.

Basically, if I go to: http://mytest.com/Home/Index

And the base project has a HomeController, with an Index Action, but the custom project has neither of those, the routing engine will be unable to find a matching View for the base controller, because the views from the base project are not being copied to the output directory.

Conclusion

Basically I'm just looking for some general guidance. Am I looking at this the wrong way? Is it worth doing?

Also, if you find any misconceptions, please do correct me!

Thanks for your time.

4

1 回答 1

1

这对于 MVC 来说一点也不奇怪。事实上,它非常常见。只需创建一个类库并将您的模型、控制器、辅助类等放入其中。然后,您只需将此类库添加为其他项目中的参考。唯一复杂的一点是共享视图,因为默认情况下不编译 Razor 视图。但是,为此,您可以使用Razor Generator

于 2013-07-31T17:11:02.943 回答