MVC and separate projects

本秂侑毒 提交于 2019-12-04 19:07:58

You are going in the right direction. In fact, for all but the most trivial projects, I like to have my model in a separate class library. And then, as you mentioned, you can reference the class library from your MVC project and use your model classes. The benefit being once you have your model ready and polished in a class library, you can "expose" to any kind presentation layer such as your MVC project or Windows Phone 7 or expose through WCF.

Keep in mind though that repositories are NOT part of your model. They are a persistence concern and they should only do the CRUD operations, plain and simple. Any kind of manipulation should go in the models layer.

You would create libraries with the tools appropriate to your implementation technology. For example, with Java you would create jar(s) containing the models. You would put the jars on the classpath of whichever project(s) used them; once you do that you have access to the library.

This is a good (great) idea if you want to reuse the model objects and business requirements they implement in more than one place. Perhaps you want customers to use your model API to implement their own sorts of clients, for example.

You could maintain the model layer as its own project, or keep it in the 'main' project and have build processes to produce the desired artifacts. You haven't given us enough information to give a hard answer on what the best approach is.

I can say this: most projects start with all the layers within the one project. If a part of the project becomes significantly complex, you can refactor out separate projects--On some projects I have seen, the web client is sufficiently complex to be its own project with its own development team (and its own MVC layers). On other projects, the entire MVC stacks were all in one project. Note that you do not need the M in MVC to be in a separate project to follow the paradigm. You just need to handle all the concerns in the correct layer.

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