Running background tasks in ASP.Net Core

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

КОМЕНТАРІ • 23

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

    Hello Dan, i came across your channel through your Video about strongly-typed Results. Like your detailed work and the good explanations. Keep up.

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

    Thanks for information.

  • @romeromedeiros3287
    @romeromedeiros3287 2 роки тому

    Awesome, thank you very much!!

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

    Thanks always for the way you make difficult subjects appear easy. It's same thing in all your videos.
    I also want to ask, assuming I want to run different background services?
    May be :
    1. To send birthday messages daily
    2. To send expired invoice reminders.
    I assume I can do that in one background service, whats your opinion?

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

      I would stick to the single responsibility idea and create one background service for a group of actions that have the same reason for change. Sending birthday wishes and sending notification for expired invoices are two different business areas, so I would suggest having a dedicated service for each of them.
      Obviously, you can have an EmailSenderService that's responsible just for the technical part of sending emails. And you' inject this EmailService in both of the services mentioned earlier.

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

      @@Codewrinkles Thank you !

  • @nikolaymarchin9296
    @nikolaymarchin9296 2 роки тому

    Hi, I really enjoy your videos, keep up the good work! What approach would you take if you wanted to execute the background service at certain time every day?

    • @Codewrinkles
      @Codewrinkles  2 роки тому

      There's also an option to set the Timer based on a CRON expression. This would require a 3rd party library named Cronos that helps you with Cron based timers directly in the DI container.
      Or you could use a 3rd party library for the whole thing, which might actually be easier. There are plenty of them out there but in my projects I usually use Hangfire.

  • @Radhakrishna-pq3yj
    @Radhakrishna-pq3yj 3 роки тому +1

    You are looking into swagger sample example output.. default values are just showing how the output will be shown in swagger... 🕺 The actual executed output is just above that.. . You got confused 😐

    • @Codewrinkles
      @Codewrinkles  3 роки тому +2

      Yes, I noticed this too after uploading. Seems I was too tired when recording. Sorry for that.

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

    I also hope you do a video on hangfire soon. Thanks.

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

      Thinking about this for a longer time. Will probably do.

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

      @@Codewrinkles Thank you!

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

    Can you use this to automatically execute an API POST method that sends data to another api?

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

      Sure, in a background service you can do whatever you want. You can use an HttpClient to make calls to an API if that's what it's required from the background service to do.

  • @habbabbutt3447
    @habbabbutt3447 2 роки тому

    Sir i want my background service to be run everyday at 9 AM to 2PM on every 40 minutes of intervals how could i do that

  • @qqquery3840
    @qqquery3840 3 роки тому

    Hi Sir. Can you make it to blazor too?

    • @Codewrinkles
      @Codewrinkles  3 роки тому +2

      For Blazor Server, sure. It works exactly the same. It's the same hosting model as regular ASP apps. For Blazor WebAssembly we don't jave the concept of background services as those apps run in the browser. Like Angular, or React for instance. However, if you server your Blazor WebAssembly App from an Asp.Net Core host, then once again you can configure as many background services on the host as you need. But they are totally separated from Blazor itself.
      Bottom line: Wherever you have a .NET Core IWebHost running, you can add background services to it.

  • @mushroomhead5914
    @mushroomhead5914 2 роки тому +1

    Bro, U didn't show us IWeatherForecastService. What a fail

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

      public interface IWeatherForecastService
      {
      public List Forecast { get; set; }
      public WeatherForecast CurrentWeather { get; set; }
      }