Make More Efficient ASP.NET Core Apps with CancellationToken

Поделиться
HTML-код
  • Опубликовано: 6 сен 2024

Комментарии • 7

  • @gavilanch3803
    @gavilanch3803  Год назад

    Get my ASP.NET Core and React course: felipe-gavilan.azurewebsites.net/api/Redireccion?curso=react-and-asp-net-core
    Get my ASP.NET Core and Angular course: felipe-gavilan.azurewebsites.net/api/Redireccion?curso=angular-and-asp-net-core
    Get my C# course: felipe-gavilan.azurewebsites.net/api/Redireccion?curso=csharp-eng
    Get my Udemy courses with a discount: www.felipe-gavilan.com/cursos?idioma=eng

  • @MaxSupercars
    @MaxSupercars Год назад

    Great videos! Quick, brief and covering everything important! No boring stuff around... Good job! Thanx! 😊

  • @James-xz1ci
    @James-xz1ci Год назад +3

    In a common MVC structure, we have controller, service, and repository layers.
    And we need to pass this cancellationToken parameter to every method?

    • @gavilanch3803
      @gavilanch3803  Год назад +2

      I'm not sure if there are other alternatives. Maybe there are, but I'm not aware

    • @user-dc9zo7ek5j
      @user-dc9zo7ek5j Год назад

      James, there are 3 ways that I can think of for handling cross cutting concerns such as this one:
      1. Setting a variable in thread local storage in middleware and getting the value from the thread (ThreadLocal) on every action that you want to. This way each service can access this variable without passing avoiding parameter pollution.
      2. Using HttpContextAccessor and accessing it on every service that wants the cancellation token, avoiding parameter pollution.
      3. Creating interceptors for each class that we want to pass the cancellation to, configuring them via dependency injection to take HttpContextAccessor and once their methods have been called to pass down the cancellation token to the base methods. Most commonly, the only external dependencies are EF Core, HttpClient. Both classes have built-in support for intercepting, the EF core interceptors are called "interceptors" and the HttpClient ones are "handlers". This is the best approach in my opinion, only needing to register both in the composition root (Program.cs) and not touch the business logic. They need to be scoped though.

  • @user-hp3wc9pr2p
    @user-hp3wc9pr2p 2 месяца назад

    i have a question. It is mandatory to pass token from controller to repository, it there any way shorter because i want to use them in repo only ? I found a suggestion that use addScope(). It will be injected to repo instead, do you have any suggestion or any solution for this ?

  • @tahaozturkk
    @tahaozturkk Год назад

    It's a legendary video thank you very useful, I have two questions:
    1) If my select method is querying about 1 million data and when I press cancel, if the query goes to the database, will the process stop in the database too? (I don't think so, but I thought maybe there is a different mechanism)
    2) If I bind the query to a button on a web page, will it be enough to close the browser to cancel the processing, or should I put another button that sends the canceledtoken then stops the process ?