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 😐
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?
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.
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?
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.
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.
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.