Middleware Pattern For HttpClient With Delegating Handlers

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น • 53

  • @ThrottleScotty
    @ThrottleScotty ปีที่แล้ว +6

    Excellent timing - I just completed the Authentication section of your Pragmatic Clean Architecture course and wanted to learn more about this point specifically. Thanks!

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Awesome, glad this was helpful to add more details 🔥

  • @MilanJovanovicTech
    @MilanJovanovicTech  ปีที่แล้ว +1

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

  • @johnnyirish9852
    @johnnyirish9852 ปีที่แล้ว +1

    Very nice video on an interesting topic. Ideas for continuing on this: write unit tests for this, write a handler that manages redirects (I think that would need to be the lowest handler, and be a different type than DelegatingHandler)

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Where would we be redirecting? 🤔

    • @johnnyirish9852
      @johnnyirish9852 ปีที่แล้ว

      ​@@MilanJovanovicTech It would be for example a handler that just logs redirect links. in the case you navigate to a link provided by the user and you want to log potential redirects, when you try to download from the user provided link.

  • @quocboy159
    @quocboy159 ปีที่แล้ว +1

    this is brilliant. I was wondering if you could help me explain when we should use transient, scope, and singleton in DI for the practical case?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +2

      Transient - stateless and lightweight services
      Scoped - one instance per scope (an HTTP request is a scope)
      Singleton - one instance per app

  • @nove1398
    @nove1398 ปีที่แล้ว +1

    Clean thumbnail, really good content.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      You like the thumbnail? I started working with an editor

  • @mentalmadness9783
    @mentalmadness9783 8 วันที่ผ่านมา

    Why is this better than doing all the steps for example inside of my Function in Azure Function App? What is the upside of doing it before anything?

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 วันที่ผ่านมา

      Reusability. Why don't we place all the ASP .NET middleware in the controller endpoint?

  • @kodindoyannick5328
    @kodindoyannick5328 8 หลายเดือนก่อน

    Thank so much Milan. I understand better this concept with your explanation.

  • @microtech2448
    @microtech2448 ปีที่แล้ว +1

    Let's say there are 3 external APIs meaning their base address, authentication process would be different and only one of them would be called based on user input. In that case how would you register them in the startup with message handlers without duplicating code? Thank you.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Create an extension method that will apply the specific message handlers. But you will still have to call that method for each HttpClient.

  • @DivljaVoda
    @DivljaVoda ปีที่แล้ว

    I have a problem with this approach, i am logging the request and response that go trough httpClient. I need a scoped Service that logs the data. The problem is that the Scoped service contains properties that are same for the httpRequest comming trough api, controllers, services and httpClients that are called within. The problem is that the scoped logging service is somehow out of scope in the DelegateHandler, i tried HttpContextAccessor, it works when the requests come from API, but the problem comes up when the httpClient is called from a background task, scoped logging service is out of scope - therefore the properties that i have are lost when called within delegation handler. How do i solve that problem, do you have an idea?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      That's a design smell to me. Can this be re-implemented to consider that there is no HttpContext in the background task?

  • @TheRealBenSanders
    @TheRealBenSanders 11 หลายเดือนก่อน

    This helped me so much. What Theme are you running with?

  • @codecam9213
    @codecam9213 ปีที่แล้ว +1

    how to solve this : Bearer error="invalid_token", error_description="The signature key was not found" when using http client in blazor

  • @pigrebanto
    @pigrebanto 9 หลายเดือนก่อน

    Maybe it is more naive apporach but there is also a way to nest Http Handlers within constructors; something like:
    var client = new HttpClient(
    new myHttpMsgHanlder_1(
    new myHttpMsgHanlder_2(
    new HttpClientHandler()
    )
    ));
    how do you see it?

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 หลายเดือนก่อน +1

      Still prefer using the recommended approach

  • @10Totti
    @10Totti ปีที่แล้ว +2

    Best tutorial!

  • @jaans3712
    @jaans3712 ปีที่แล้ว +1

    Do you have a video about Keycloak? Interesting topic

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      No, I don't have a Keycloak video on the channel. However, I did cover Keycloak in the Auth section of my course. But it's not free 😅

    • @jaans3712
      @jaans3712 ปีที่แล้ว +1

      @@MilanJovanovicTech you salesman!

  • @pigrebanto
    @pigrebanto 9 หลายเดือนก่อน

    did it fail after 2 times? shouldn't have been 3 times the retry instead? tks

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 หลายเดือนก่อน +1

      Yes - I might've sped it up for the presentation :)

  • @Th3MoL3
    @Th3MoL3 ปีที่แล้ว +5

    Hmmmm......i was getting a bit of déjà vu as i was thinking i had seen this in a video already very recently. Nick Chapsas literally had a video talking about this 4 days ago....maybe its a coincidence 👀

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      It is, I schedule my videos 2-4 weeks in front 📆📆

  • @pp-studio
    @pp-studio ปีที่แล้ว +1

    Thank you for your content.

  • @techpc5453
    @techpc5453 ปีที่แล้ว +1

  • @clashclan4739
    @clashclan4739 ปีที่แล้ว +1

    Title misleading where decorator pattern?

  • @ronaldabellano5643
    @ronaldabellano5643 ปีที่แล้ว +1

    Why cant save?

  • @altkev
    @altkev ปีที่แล้ว

    I hope one day videos with goofy faces on thumbnails attract less clicks so that trend can go away. This is a programming channel, do these types of viewer's even click more from that?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Then you're hoping for human psychology to go away, and well... that isn't really happening. 😅
      What does it matter anyway? The content is what's important. If you like it, you'll watch it. If not, you'll stop watching.

    • @altkev
      @altkev ปีที่แล้ว

      @@MilanJovanovicTech Well my comment is a sign that its resulted in me thinking about and focusing on your thumbnail enough to comment about it, so if that's a positive thing for the channel due to the additional engagement, then I suppose there is no incentive for change. But I will say cringe titles/thumbnails can be polarizing.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      @@altkev Okay, but does the content deliver on the value? Because if it doesn't, I'm doing something wrong.
      My other option is doing "normal" thumbnails and getting 30-50% less views. :(
      TH-cam is saturated. Right now, there isn't any other way to stand out.
      P.S. You may want to skip next Friday's video. Quite an awesome thumbnail if I may say so myself, but probably not to your taste. 😅

    • @altkev
      @altkev ปีที่แล้ว

      ​@@MilanJovanovicTech 30-50% less views just by not putting your face on there is extreme. Well regardless of my personal tastes and desire to comment on it, you should certainly do what you need to for your channel's success. My comment was more of a commentary that it is unfortunate that such strategies have to be used in the first place.

  • @DaliborHomola
    @DaliborHomola ปีที่แล้ว +1

    Thank you, this really helped me 🤎