Repository Pattern with C# and Entity Framework, Done Right | Mosh

preview_player
Показать описание
Want to learn more from me? Check out my these links:

Confused about the repository pattern? This tutorial explains it all.

There are many tutorials about the repository pattern and many of them are conflicting. If you've been confused about the proper way to implement the repository and unit of work patterns with Entity Framework, this video is for you.

00:00 What is the Repository Pattern?
00:47 Benefits of the Repository Pattern
03:50 Repository in a Nutshell
04:47 What is the Unit of Work Pattern?
05:00 Does Entity Framework Really Implement Repository and Unit of Work Patterns?
09:31 Clean Architecture
11:43 Implementing the Repository Pattern
14:09 Implementing the Unit of Work Pattern
15:09 Repository and Unit of Work Patterns in Code
22:49 Example of Repository and Unit of Work Patterns

Download the source code for this video here:

And here are some YouTube videos of mine you might be interested in:

Event and Delegates in C#

Generics
Рекомендации по теме
Комментарии
Автор

It's amazing that what Mosh taught here in 2015 still holds true in the first day of 2020. Cheers!

mikedqin
Автор

You say that your CourseRepository knows nothing about EntityFramework, however, it is strongly coupled to EntityFramework, because it's base class, Repository<T> injects a DbContext, which is EntityFramework specific. If you remove the `System.Data.Entity` reference, and swap it with another ORM, the whole things breaks. So it's wholly dependent on EF, from the generic base class, upwards. You should really name your generic repo as `EntityFrameworkRepository<TEntity>`, to show that it is dependent on EF. But this will still mean the app breaks when you swap ORMs. It would just make it more clear, as to why.

ApacheGamingUK
Автор

Mosh, I don't know if you still read this but I wanted to say THANK YOU for taking the time to go over the arguments that EF already implements the repo pattern, etc etc, and demonstrate that this is not exactly the case. This entire debate had me so confused for quite a while, and you did a _great_ job putting it to rest (for me, at least). The demonstration is also nicely done. Thanks, really.

marc
Автор

Excellent. Probably the clearest, most concise, and easiest to grok tutorial on the Repository Pattern I've ever watched.

BryanJohns
Автор

I've listened to many Mosh tutorials over the years, and this one is still the most impressive to me... he says the same things as many other videos, but the cadence along with the presentation queues simply flow better here. It's why I've come back to listen to it repeatedly... it's also superior in quality vs an average college lecture.

hardryv
Автор

I have done repository before and I am new to unit of work. My repositories have save and delete methods. The way you explain unit of work here has helped me a great deal I will be implementing this pattern much more often.

Thenbafan
Автор

Find method in IRepository<T> is breaking the rules of having the query written only once. A developer can inject any expression in it duplicating queries in different repository clients.

I'd remove it from the interface and allow only named query methods. Specification pattern might be an alternative option but that in the end kind of boils down to the same thing.

milanimilivoj
Автор

I was searching 2 days for guide like that and everything was a trash, lessons without understanding the base... and only now youtube proposed me this video and it's perfect!!! My huge respect to author !!! Like and subscription :)

kuroki_suzume
Автор

The number one ! I have about 4 Mosh courses on Udemy. They all help me today.
With that I gained better job opportunities. Thank you!

FabioCordeiro_RJ
Автор

Your "IRepository<T>" has "Find" method with "Exspression<Func<T>, bool> predicate" parameter. How are you going to implement it with stored procedures?

mykhailo-kmet
Автор

The best video I've seen for repository pattern - clean and simple.

Pest
Автор

This is, truly, the best resource on the subject that I've seen. Thank you

david
Автор

"simplicity is the ultimate sophistication" and your training also simple & Clear about a complex pattern.

jobycheriyan
Автор

Best explanation I've yet to see of the repository pattern.

pierrenilsson
Автор

The way you explain things is so uncomplicated you almost make it seem like this stuff is easy. Thanks a load mate. Your tutorials are excellent.

kingmaduma
Автор

What if id is type of Guid, then your generic repository will not work. Here is iEntity comes to play. Your domains should inherit from iEntity<T>, so you can query based on id

Автор

I was about to not use repo pattern on my project because of other videos saying it was redundant, but your explanation made so much sense and was really easy to understand, thanks for taking the time to make this video.

kevina
Автор

These is the best tutorial i have found that explains a concept i have been trying to grasp for the last 2 weeks. Very precise and explains everything in details.

matigarimanjirungi
Автор

This channel is gold mine for C# Beginners and Aspirants.

gauravpathare
Автор

Saw dozens of tuts but literally this was awesome simple and focused, I feel confidence now. Thanks a lot!

sohailarshed