Building a Dapper CRUD API From Scratch In .NET 7 - For Beginners

Поділитися
Вставка
  • Опубліковано 15 вер 2024

КОМЕНТАРІ • 94

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

    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

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

    Milan, I work at a company that heavily relies on Dapper, although in a somewhat anemic domain. While attempting to implement a Rich Domain using DDD's tactical patterns (such as value objects, entities, aggregates, etc.) in some projects, I encountered significant challenges when it came to mapping my aggregates with Dapper. Consequently, I ended up utilizing reflection and protected constructors with signatures that match the projection. It would be incredibly insightful if you could create a video discussing how to effectively leverage Dapper in such scenarios. Your freely shared content on UA-cam is greatly appreciated.
    P.S. I'm thoroughly enjoying your Pragmatic Clean Architecture course!

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

      I actually made a video about this a while ago, talking about the Snapshot/Memento pattern 👇
      ua-cam.com/video/HhZ4DtON404/v-deo.html
      P.S. If you get value from the course, it would mean the world to me if you leave a testimonial. ❤️

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

    It would be good make a new video improving this API, spliting it in layers (Repository, Services, ...) and implementing unit tests.

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

      Perhaps, but this is enough for a beginner to get started

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

      Please take it to the next level

  • @kodindoyannick5328
    @kodindoyannick5328 7 місяців тому +2

    Clean and efficient! Thank you Milan.

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

    Didn't know about the option for route groups, thanks for showing us that . Would love to see how you would unit test this.

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

    Super simple, clean and efficient.....
    I haven't messed with Minimal APIs that much(I guess once back about 1+ yr), Thank you for making this.
    However, I would rather stick with EFCore+Automapper(I hope you will do a video about it too) to avoid raw SQL queries/stuff.

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

      I despise Automapper 😁

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

      @@MilanJovanovicTech interesting.😊 but curious to know why??
      btw I'm trying out Dapper wih different DB Providers(I mostly use Mysql/Postgres), I maybe move an old project that uses direct sql queries with cmd to Dapper(while migrating it to dotnet 7)

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

    Great introduction please take it to next level , and show how to get the same featurea in ef core like change tracker , logging , exception handling and more❤

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

    Hi Milan, can you please make a video about "vertical slice architecture" maybe with comparison to clean code archecture and which you would prefer and when?

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

    I am from Egypt and I have been following the channel for a long time. I would like to thank you for that great explanation, Engineer Milan. I hope that you will give me your social media links to follow all your posts.

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

    Superb. Thank you.

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

    Hey, thanks for the video. Could you please give more details about not to register a SqlConnectionFactory as a singleton service? I dont understand provided example.

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

      The .Addsingleton is used coz the connection to the database is established once my application session(at the start) and the re-used as a connection pool.

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

      It can be a singleton also - just not if you want to store and reuse the current connection inside.

  • @andreyz3133
    @andreyz3133 Рік тому +4

    is not it better to inejct IConfiguration inside SqlConnectionFactory and get connection string inside rather than pass it as parameter? or it is better in terms of isolation to make it like this?

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

    Please do more videos like this where we see you write code from the beginning

  • @hussainimca
    @hussainimca 4 місяці тому

    Excellent video. I left .Net probably 8 years ago. wanted to learn quickly .net 8 core as we have a requirement in our company to build application in .Net 8 with Blazer, Syncfusion, MVP framework. Is there a video or tutorial on how to quickly upgrade skills. I do not need to be an expert but decent knowledge is fine.
    Appreciate your help.

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 місяці тому

      I doubt such a video exists

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

      Hi brother, I am also in the same situation like you, have you found any good resources?

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

    How can we merge Clean Arquitecture and DDD with Dapper instead of EF Core?

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

      Put all your SQL logic in repositories that get called by either Application layer services or CQRS commands and queries.

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

      It'a definitely harder, since there is no UoW. One option is the Snapshot pattern.

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

      thx i do a little research on that@@MilanJovanovicTech

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

    What do you think of relationships using dapper and having nested objects in C# based on the relationships?

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

    What would be the difference between creating a controller vs using minimal api if we are moving the code from program.cs?

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

      Will you have 200 endpoints in Program.cs?
      Minimal APIs are more performant

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

    Really good explanation, however I feel like this Dapper thing wanting literal TSQL strings is really insecure and hellish to maintain in the future

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

      You can easily use Stored Procedures with Dapper too if you prefer to not have TSQL littered about in your code.

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

      It's not insecure at all when used properly with parameterisation (Marc Gravell wrote a blog post in 2017 on the subject if you want to read more on that), however I agree that the use of inline SQL is what really turns me off using Dapper.

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

      Not if you usr parameters

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

    Thank you for great explanation. I am following all of your videos and they are really great. One question though: what’s the point of using minimal apis if we encapsulate all our endpoints in separate class? Is the same if we use controllers. Why do you create CustomerEndpoints instead of CustomersController? Thank you

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

      Where else would they live? 😁

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

      @@MilanJovanovicTech fair question :)) in my opinion, minimal api was introduced to reduce responsibilities to API and create micro services. E.g. customers service is containing only endpoints for customers and that’s all. All of the related endpoints i guess would be in program.cs. But anyways, i agree on your choice to organize the code the way you did, i was just wondering if you had more reasons to do so. Thank you for your videos, your progress is remarkable

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

    Unfortunately it is only half of the way. How do I call the API from my application and how do I retrieve the data or send data to the API?

  • @johnormaric3350
    @johnormaric3350 11 місяців тому +1

    Did you use Dapper here both to connect to the database and to execute APIs?

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

      I think the answer is yes (from my understanding of your question)

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

    You should also do a video using dapper rainbow

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

      Interesting, will explore some more 🤔

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

      @MilanJovanovicTech not a lot of documentation, but I love it. The only problem is that it keeps private, the transaction, so you can't combine it with your own queries without turning to reflection. But I don't see you use transactions, so you may be in the clear :-p

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

    Thaks a lot. Can I creating a Database with Code First in minimal API project ?

  • @oneminutecoder
    @oneminutecoder 4 місяці тому

    Maybe I don't want any improvement. I just want to make a simple application. It's okay if many things are on a single page. I might not need new complications.
    Sometimes improvements serve no purpose other than adding complexity. It's better to keep it simple unless necessary. If needed, we can deal with improvements.
    Perhaps the person who comes after me will understand this code better if there are no improvements.
    Everyone doesn't have to know everything. People have other things to do as well.

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

    Hello, I am creating a project using dapper with onion architecture. Since I was using Dapper, I could not adapt the identity and jwt token packages to the project. Can you help with this?

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

    what's the theme you are using in visual studio? i like it

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

    Are there no vulnerabilities, like SQL Injection?

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

    شكرا لك

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

    finally!

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

    Hi! In your new course, i was reading the curriculum and i have a doubt. In this course, you talk about modular-monolith and integration events? Thanks you a lot for the content!

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

      The course is focused on building a monolith, in a modular way. There is only one module, however. I didn't want to overwhelm the student with complexity.

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

    Why did you pick up dapper now instead EF? Are you having issues with speed?

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

      yes, thats the reason Dapper is being preffered, the performance. EF is too slow but more complex

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

      @@azad2096 In past I knew EF was bad in performance but the new version I think are fine.

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

      No, I want to talk about different options

  • @user-xm7sh3vw8o
    @user-xm7sh3vw8o Рік тому

    Hello, I have a question, the order is created, and the orderItem is created at the same time. Is the creation of the orderItem operated in the orderCommandHandler or what? Or modify the inventory, where should I go to operate? looking forward to your reply

  • @user-xm7sh3vw8o
    @user-xm7sh3vw8o Рік тому

    It would be better to add two conditions to the query, that is, the conditions may not be spliced into SQL

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

    Really informative videos dear Milan! Thank you for your hard work.
    Can you please tell me if can we use same api controller to cater different countries by using countrycode in url?

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

      As a query parameter? Seems doable

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

      @@MilanJovanovicTech Thanks for your reply 🙂👍 What should be the best practice for such scenario.🤔 I dont want long if else statements

  • @minaemad-c7y
    @minaemad-c7y 6 місяців тому

    plz explain why singlton not scoped ??

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

    Hi Milan! How do you approach many to many relationships in DDD with ef core? Most examples in the Internet only show one to one and one to many. Some people use owned relationships. But no-one shows how to do that with many to many relationship.

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

      Do you even need such a concept (other than in the DB) in your domain model? Because most problems can be solved without it, and it's simpler

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

      @@MilanJovanovicTech Do you know any good articles about this? You're right in a sense that I may not need such concept in domain models (still don't know how to do that). However, my domain models are also the models I save in the database (I know that ideally they should be different, but honestly I haven't seen any good example on GitHub). Maybe you could make some video where you try to model some tricky relationships, etc.?

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

    De Milane, imaš li link od git repositorija za ovo??

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

      Nemam ovo, ali imam neke primere ovde: github.com/m-jovanovic/

  • @ShivamSingh-gu1hn
    @ShivamSingh-gu1hn Рік тому +1

    which theme are you using?

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

    It's all fun and games until you get enormous tables containing 100+ of columns. Is there a way of deal with them using Dapper without having to write the whole sql?

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

      Will you always need 100 columns?
      There are SPs for something like that, and you clean up the code