✅ Help needed: ensuring synchronization on startup for Minimal API app
I have a Minimal API application that I need to execute code on during startup. This application synchronizes changes between two systems. If the application has been offline, it must check for any missed changes as soon as it starts.
12 Replies
Is it okay if this happens during API startup, or must it be done before?
Thanks for your fast response; I think it should happen during API startup – it should not be a separate application.
yeah but when
as in, must this be done before the API starts the http listener?
or is it fine if the API is up and running a few seconds before the sync finishes, potentially
if you dont care about the timing, a
BackgroundService
is by far the easiest way to "run some code" at program startupI need to think about it.
So a BackgroundService will run at the same time as the API is listening?
yup.
And it can run some code at program startup. I appreciate your help.
it starts at the same time as the asp.net host starts
so all you do is make a
class YourSyncService : BackgroundService
and implement the async Task ExecuteAsync(CancellationToken ct)
method
and finally add it to your service collection: services.AddHostedService<YourSyncService>();
thats all.I understand. Thanks for your assistance.
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
I understand, @TeBeCo. Thanks for your response!
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Okay, I'll make sure to test it.