The Repository Pattern explained for EVERYONE (with Code Examples) 🚀

Поділитися
Вставка
  • Опубліковано 24 лип 2024
  • 🚀 Join the .NET Web Academy: www.dotnetwebacademy.com
    ➡️ Use code START2024 for 10% off!
    💖 Support me on Patreon: / _patrickgod
    🚀 Get the .NET 8 Web Dev Jump-Start Course for FREE: dotnet8.patrickgod.com
    🐦 Let's get social on Twitter/X: / _patrickgod
    🔗 Let's connect on LinkedIn: / patrickgod
    🚀 .NET Jumpstart Course: www.udemy.com/course/net-core...
    💻 GitHub: github.com/patrickgod/Reposit...
    🔥 Blazor E-Commerce Course: www.udemy.com/course/blazor-e...
    🔥 Blazor Bootcamp: www.udemy.com/course/blazor-w...
    Table of Contents:
    00:00 The Repository Pattern explained for EVERYONE 🚀
    00:23 Repository Pattern Definitions
    02:47 Code Example with a .NET 7 Web API in C#
    04:29 Build a Repository
    06:37 Inject the Repository in the Controller
    08:19 Register the Repository/Service
    10:10 One More Beauty of Dependency Injection & the Repository Pattern
    🙏MANY THANKS TO THESE LOVELY PEOPLE:
    Nathan Waterman
    Rakesh Bridgraj
    Joaquim
    Ralf Kürbitz
    @jacoviza
    Thomas McMeekin
    Ameet Jayawant
    JesperNielsen
    Paul
    @Alaffer
    Alvin Majid
    Slava Ukrayini
    Piotr Franczak
    Jan Trichter
    Tom
    H. Ali
    Ashley Gahl
    Daniel Viveros
    Mehmet Ali Ege
    Winther
    harry j
    @Alaffer
    Sam Catlow
    Jim
    Brian Williams
    Gonzo
    Jonas
    Ariel Sartor
    Andy Benson
    @stevelikespies
    Raphael Lukas
    James Goforth
    @williamdevine
    Doug Nelson
    Arif Hasanov
    @kohji1712
    @dlb78dlb
    Thomas Korsgaard
    FastTrak
    Jeff Sager
    Dan Moyer
    AlgoMarket
    Mennskr
    Simon
    Michael Mel
    Hermann Rösch
    Jim McNeal
    Kieron
    @mgrainger231
    Gerrit Esmeijer
    Axel
    Kareem Skinner
    Joaquim
    Alain Legrand
    Per Rieland
    @prodrigu75
    Greg
    Brendan Maunder
    Stageoner
    Andrew Campbell
    pascalditzfeld
    PovilasSimanskas
    jenö
    Marco Otilli
    Mark
    l33ter
    alibux
    g.dassel
    Luke Vincent
    mrcl
    Alain Legrand
    Thomas Werner
    István Csibor
    Grant Burdon
    @gianluigiconti
    Gerrit Esmeijer
    Illia
    Németh-Pók István
    Michael Mel
    Marko Zdilar
    GerryB
    @DADA_universe
    Domen Hren
    @heroesch
    Carey
    Peter De Tender
    Baris Keskin
    @Big_Bear_27390
    Mathias
    walter e watkins
    Günther Dassel
    Axel
    Josh
    Daniel Huber
    Fredric Adell
    Juan Carlos
    Manolis
    Pajani
    P.
    Jonas Granlund
    Bobby
    Kristina
    @xamarin007
    #DotNet #RepositoryPattern #PatrickGod

КОМЕНТАРІ • 60

  • @PatrickGod
    @PatrickGod  11 місяців тому

    🚀 Join the .NET Web Academy with a 30% discount - closing soon!
    👉 www.dotnetwebacademy.com/courses/academy?coupon=dnwas23yt

  • @VictorPraizTech
    @VictorPraizTech Рік тому +43

    I came here for the understanding of repository pattern but left with a full understanding of dependency injection. 😅 something I’ve been struggling to understand for weeks. Thanks man.

  • @Apfelloch
    @Apfelloch Рік тому +9

    Came for a Repo Pattern explanation, stayed for the Dependency Injection explanation. I've watched several videos but it was yours that finally made it 'click' for me. Great example - not too abstract (as those "DI explained in n minutes videos) but also not too complex for beginners like me.

  • @38911bytefree
    @38911bytefree Рік тому +1

    Thanks Patrick. I have been trying to learn this yesterday and this vid really clarified some points.I have been following several of you vids, Love the way you exlplain in such a peaceful way. Thanks Sir.

  • @knightmarerip711
    @knightmarerip711 Рік тому +1

    I like how this was explained without using EF, Dapper, etc... just focused on the design pattern. Very well explained!

  • @seva2814
    @seva2814 Рік тому +7

    Thats actually not a Repository Pattern, that isolates the database connection but a service layer

    • @theonlycaulfield
      @theonlycaulfield 10 місяців тому +1

      Yes, I am confused on how this is the top result for my query on ".net repository". A repository pattern separates the db connection from the logic in the service layer. This video represents the repository pattern as if it is the thing that the repository pattern is intended to prevent.

  • @qemajlosmani
    @qemajlosmani 11 місяців тому

    Gut gemacht. Simple and very well put example. I always structure the code and pattern design like this.
    When you have too many services, be careful. Injecting services into each other in a circular manner can lead to runtime errors like stack overflow or infinite loops. It's best to avoid such circular dependencies and design your services in a more decoupled way to ensure proper functioning and maintainability. Otherwise, best way to go 👏🏼

  • @Bhupin
    @Bhupin 10 місяців тому +1

    Thank you so much for this...I came to learn Repository Pattern but learned Dependency Injection..I wish I could tell you how much i struggled trying to grasp the concept of Dependency Injection..You have a new subscriber sir!!

    • @PatrickGod
      @PatrickGod  10 місяців тому

      Wonderful! Thank you so much!

  • @HedgarBezerra
    @HedgarBezerra Рік тому +1

    I really like this pattern along with some more abstraction, in manner that we code a abstract class with generic parameter(class) with all data access functions, this could be reused for all entities around the application.

  • @sthreetorch
    @sthreetorch Рік тому

    Point by point. Very well explained! Thanks a lot Man (Additional Subscriber)

  • @manuelgamezz
    @manuelgamezz Рік тому +2

    Thanks Patrik, good example.

    • @PatrickGod
      @PatrickGod  Рік тому

      Thanks Manuel, glad I could help!

  • @noahg2
    @noahg2 Рік тому

    explained in the best possible manner, thank you very much.

  • @andrewsotnikov5680
    @andrewsotnikov5680 Рік тому

    Good example, it also touches the basics of DI

  • @jannickbreunis
    @jannickbreunis Рік тому

    I am studying how to create multiple data acces classes to prevent having one enormous data acces class. I found the Service Pattern and Repository Pattern. I guess with creating an interface, you combine the two? Good video and nice combination of also showing the depency injection.

  • @normanaranez323
    @normanaranez323 Рік тому +1

    Do you have any idea how to build multi-tenant architecture that has shared code base and a lot of database?

  • @kiransai7616
    @kiransai7616 Рік тому

    Good work sir 👍 , on your next vlog please explain us how to work on multi tenant architecture with identity.
    for example: if the client is registering he will have master data base and, he will add some worker's below him they have their own separate database.

  • @daydrivver2074
    @daydrivver2074 Рік тому +1

    Thank you, i know you just don't do the content for me (asked in a one of your videos about this) but many thank you I hope someday I can pay you back, right now I lost my job due to current environment so many thanks for the content.

  • @Untold-Stories
    @Untold-Stories 29 днів тому

    Hi Patric ,
    Please clear the below issue I am facing.
    I am creating a GET request for search function. I am sending the whole model in GET. some of the properties in model is [required]. when I am sending the model the validation working. I don't want required validation for search operation. Is there any technique to remove the validation for GET Search method. Thanks.

  • @thepatrickandlunashow
    @thepatrickandlunashow Рік тому +1

    Great video! Kristina recommended your podcasts- I am on board!

  • @kurisutinahiyajosafinaillu6595

    I have a question about registering the repository and service, if i have multiple interfaces and classes in a same folder, how can i register them quickly without having to write multiple builder.Services.AddScoped like this example:
    builder.Services.AddScoped()
    builder.Services.AddScoped()
    ...
    builder.Services.AddScoped()

  • @Toughmenchannel
    @Toughmenchannel Рік тому

    Great Video. Thanks a lot!

  • @chinmayck8509
    @chinmayck8509 15 днів тому

    Well explained brother. Got to learn more than expected.

  • @adamm9706
    @adamm9706 Рік тому +1

    Have you done the Factory Pattern? If not that would make for a great video as well

  • @kwstaslalaounis3212
    @kwstaslalaounis3212 Рік тому

    Thank you very much!!!

  • @joaogabrielv.m328
    @joaogabrielv.m328 Рік тому +2

    Keep up, Patrick! You are a real God, man :D

    • @PatrickGod
      @PatrickGod  Рік тому +1

      Wow, thank you so much! 😊

  • @phuongtran-qh5kq
    @phuongtran-qh5kq Рік тому

    Sir, i have 1 question. What about dbcontext and dbset. For example: dbset User. Should i create a repository of user and inject that user db?

  • @samiullah0011
    @samiullah0011 Рік тому

    If have 50+ controllers and services should i need to inject every class(addscoped etc) into main class?

  • @Gabrieldvg1
    @Gabrieldvg1 Рік тому

    Good video, but what is a service exactly in this context? I've seen it used in a few places but I still don't know what it is referred to :/

  • @AthelstanEngland
    @AthelstanEngland 8 місяців тому

    Thanks for this. Never really understood what bit the 'repository' was... now you say it is pretty much the service (I use same term) it makes more sense. One question if I may. Working on my first app of this type (OpenAPI) and it seems you do have to register every single interface in program.cs (using .NET 7) which seems a lot of overhead to me?

  • @byte7930
    @byte7930 Рік тому +3

    1. This looks exactly like your Udemy course I took a while ago. So I'm happy, that I'm already using it like this approach.
    2. What game cardridge is inserted into your SNES? 😀

    • @PatrickGod
      @PatrickGod  Рік тому +1

      1. Thank you so much for enrolling! 😊
      2. The Legend of Zelda: A Link to the Past 🎮 Awesome you noticed!😁

  • @ana-mariaolujic6570
    @ana-mariaolujic6570 13 днів тому

    excellent explanation, thank You Patrick

  • @10Totti
    @10Totti Рік тому +2

    Many thanks!

  • @jd-chnl
    @jd-chnl Рік тому

    Thank you for explaining! One thing I would like to comment is that your controller in the example works just like a wrapper and adds no any functionality, so I think there is no really need to implement repository here.

  • @vdotrailers
    @vdotrailers Рік тому

    what is Full repository analysis in AWS site and what does it do? can someone explain pls....is this the place where i can find my app source code in AWS?

  • @marcioalexandremarcondes557
    @marcioalexandremarcondes557 9 місяців тому

    Tks!

  • @mykhailo-kmet
    @mykhailo-kmet 11 місяців тому +4

    It is not a good explanation of Repository pattern. Repository pattern is for manipulating data as if it a collection. So any repository should have methods for adding, removing and getting data. Otherwise it is just data accessor service

  • @salmanahmedkhan3979
    @salmanahmedkhan3979 Рік тому +1

    great. subscribed.

  • @vintagewander
    @vintagewander Рік тому +1

    You deserve more subscribers

    • @PatrickGod
      @PatrickGod  Рік тому

      Thank you so much! I appreciate that. 😊

  • @gabrielmessias5072
    @gabrielmessias5072 Рік тому

    Hello, I love your videos. I have a request because it still causes me a lot of doubt, could you make a video about websocket?

  • @StevenWong1995
    @StevenWong1995 9 місяців тому

    Say if I have multiple interfaces and classes to be registered in the Program.cs, is there any way that I can do it with a smarter way instead of registering them one by one?

    • @ofskiiboy
      @ofskiiboy 7 днів тому

      You can use the Scrutor package which auto detects all your repo's and injects them

  • @tanujavalluru9195
    @tanujavalluru9195 Рік тому

    thankyou

  • @QartveliMamakaci2000
    @QartveliMamakaci2000 3 місяці тому

    Unknowingly explained Dependency Injection too lol.

  • @arunkumarsingh8754
    @arunkumarsingh8754 Рік тому

    Love from 🇮🇳 ❤

  • @babarmughal8891
    @babarmughal8891 11 місяців тому

    Best

  • @tomchidwick
    @tomchidwick Місяць тому

    I'm still confused.

  • @Faygris
    @Faygris Рік тому

    So, when using services like this, I've secretly been using the repository pattern all along? 🤯

    • @theonlycaulfield
      @theonlycaulfield 10 місяців тому +2

      No, this video perplexingly does not describe a repository pattern, as repositories are supposed to separate the db connection from the logic layer that is in the services/service layer. The author seems to be confused on this point when saying that he and others call the repository layer services. What he is doing is simply creating a service layer with the logic and db connection combined, which is what the repository pattern was created to prevent. The repo pattern is a common practice in enterprise software in the US, with both java spring and c# .net, where the intention is to isolate the db connection away from the service layer.

  • @yannid5456
    @yannid5456 7 місяців тому

    This explanation is a bit not so correct. Services and Repository are two different patterns that perform different tasks. We use service to store the business logic such conditions and data manipulations.The repository pattern is used for data operations such as database CRUD operations

  • @wilfredkane7569
    @wilfredkane7569 Рік тому

    𝘱𝘳𝘰𝘮𝘰𝘴𝘮

  • @mck9512
    @mck9512 23 дні тому

    Dude... im interested in an explanation of repository service, not DI. Stay on subject.