简体   繁体   中英

MVC 4 with repository and unit of work pattern

I knew that in mvc it is good to use repository pattern and unit of work class as design pattern in ASP.net MVC project.(Business logic in service layer.)

My question is, I am new to MVC 4 introduce by Microsoft.can I apply above mention pattern(repository and unit of work) in MVC 4 environment also,Is it good approach to start my project in that design pattern.

In MVC do I need to meet another type of pattern for large MVC project.

can anyone know about the MVC 4 please comment on that highly appreciate.

"in mvc it is good to use repository pattern and unit of work class" - this is highly questionable, while saying things like "considered one of the best pattern used out today" is plain wrong: patterns are only good or bad within some context, without which you can't really tell whether they are good choice or not.

Starting with the question "which patterns should I use" without first thinking about the specifics of the application you need to write is a sure-fire way to create an overdesigned application.

Repository and UoW have been popularized by Domain driven design , and they make a lot of sense if you go down that path. DDD is excellent approach for some applications, but I would argue that this is not a majority of applications. Many web apps are just CRUD apps which don't benefit from DDD or wrapping every access to entities in a repository - eg choosing a micro-ORM is often a saner approach here.

If you are still sure that your app really needs such an approach, instead of implementing all this stuff yourself, I suggest using a framework like NHibernate , as you will need more then just UoW and repo - they will require identity map implementation, etc. NHibernate provides a lot of things out of the box (eg its Session type is actually an excellent implementation of UoW plus much more), and covers many details which you will only find a necessity once after you go into details of implementing your own version. Entity Framework might also be a good choice here, although it is not my favorite.

Of course, writing your own is a great way to extend your knowledge, but if you need this for a production application, you will save a lot of time, money and headaches by picking an existing implementation.

Just because the Repository pattern is shown in every single Tutorial, doesn't mean its a defacto standard to solve problems in the MVC world.

First off you need to understand the complexity of your application.A Repository may add unneeded complexity to your application.BTW you have not mentioned how are you going to talk to the database.If you have planned to use any of the ORM tools like (Nhibernate,Entity framework),then you already have a good abstraction in place.Why would you need one more level of abstraction.

There is a lot of debate on whether or not to use Repository patterns.Here are some really good explanations

Do we need Repository ?

Life without repositories - Ayende

All famous ORM tools comes implemented with the patterns that you have mentioned(Unit of work and repositories).

看看在ASP.NET MVC教程中实现ASP.NET MVC应用程序中的存储库和工作单元模式 ,这应该足以让您朝着正确的方向前进。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM