No video

How to use the Repository Design Pattern in C# and ASP.NET

  Рет қаралды 11,420

tutorialsEU - C#

tutorialsEU - C#

Күн бұрын

Пікірлер: 12
@tutorialsEUC
@tutorialsEUC Жыл бұрын
🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg
@learndevtech
@learndevtech 6 күн бұрын
❤ magnific. This is way underrated!
@maryamblri
@maryamblri 6 ай бұрын
I have 8 years of experience in programming and I found this tutorial awesome. great job! please cover more design pattern like UOW and factory design pattern.
@usmanfarooq3071
@usmanfarooq3071 Жыл бұрын
What will happen if we have a complex business transaction where we are saving multiple entities in DB. How would we manage the SaveChanges method when we need a db autogenerated id of one entity as an input value for another entity in same transaction?
@TheMezanine
@TheMezanine Жыл бұрын
In case of multiples transactions, you might implement Unit Of Work on top of Repositories. The UoW will manage the DBContext and implement transactions: EXAMPLE: public class UnitOfWork : IUnitOfWork { private readonly AppContext _context; public IUserRepository Users { get; private set; } public IAddressRepository Addresses { get; private set; } public UnitOfWork(AppContext context) { _context = context; Users = new UserRepository(_context); Addresses = new AddressRepository(_context); } public UnitOfWork() : this(new AppContext()) { } public int Save() { return _context.SaveChanges(); } public void Dispose() { _context.Dispose(); } public IDatabaseTransaction BeginTransaction() { return new EntityDatabaseTransaction(_context); } } USAGE: using(var unitOfWork = new UnitOfWork()) using(var transaction = new unitOfWork.BeginTransaction()) { try { unitOfWork.Users.Add(new User(... User One ...)) unitOfWork.Save(); unitOfWork.Addresses(new Address(... Address For User One ...)) unitOfWork.Save(); unitOfWork.Users.Add(new User(... User Two...)) unitOfWork.Save(); unitOfWork.Addresses(new Address(... Address For User Two...)) unitOfWork.Save(); transaction.Commit(); } catch(Exception) { transaction.Rollback(); } }
@gregorydeclercq2990
@gregorydeclercq2990 4 ай бұрын
If you use controller-service-repository and handle the logic in the service. You (should) never get those issues
@Lonchanick
@Lonchanick 7 ай бұрын
marvelous!
@luisgonzalez8877
@luisgonzalez8877 4 ай бұрын
Excellent explanation, thank you a million. I noticed that you invoked the repository tier from the controller (presentation) tier. Is this a best practice? I believe that specific logic requires the presence of business logic; for instance, in your example, it could be for the update method...
@HenningBerggren
@HenningBerggren 17 күн бұрын
You could insert an application layer (often referred as use case layer) where you would implement all your business logic (critical and application logic), but this is merely for larger applications.
@kriskata7653
@kriskata7653 9 ай бұрын
Okay but what If we use services? I mean this repository pattern does the exact same thing as having a service. So I don't think this pattern makes sense in this case.
@gregorydeclercq2990
@gregorydeclercq2990 4 ай бұрын
Are People using context in controllers?!
Singleton Design Pattern in C# - Do it THAT way
13:15
tutorialsEU - C#
Рет қаралды 25 М.
Repository pattern in asp net core
14:50
kudvenkat
Рет қаралды 302 М.
Can This Bubble Save My Life? 😱
00:55
Topper Guild
Рет қаралды 85 МЛН
English or Spanish 🤣
00:16
GL Show
Рет қаралды 7 МЛН
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 13 МЛН
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 155 М.
Understand your C# queries! IEnumerable & IQueryable in explained
11:28
tutorialsEU - C#
Рет қаралды 35 М.
Паттерны. Репозиторий и сервисный слой
7:22
Repository Pattern
11:08
Coding Concepts
Рет қаралды 67 М.
Repository Pattern in ASP.NET CORE
11:56
ASP.NET MVC
Рет қаралды 36 М.
Repository Pattern with C# and Entity Framework, Done Right | Mosh
26:24
Programming with Mosh
Рет қаралды 870 М.
ASP.NET Core Crash Course - C# App in One Hour
1:00:44
freeCodeCamp.org
Рет қаралды 1,5 МЛН
.NET and C# are in trouble. Here is what I'd do.
10:57
Ed Andersen
Рет қаралды 39 М.
Understand C# LAMBDA Expressions in only 2 minutes!
4:22
tutorialsEU - C#
Рет қаралды 53 М.
Can This Bubble Save My Life? 😱
00:55
Topper Guild
Рет қаралды 85 МЛН