C
C#6mo ago
Eple

✅ 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
Pobiega
Pobiega6mo ago
Is it okay if this happens during API startup, or must it be done before?
Eple
EpleOP6mo ago
Thanks for your fast response; I think it should happen during API startup – it should not be a separate application.
Pobiega
Pobiega6mo ago
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 startup
Eple
EpleOP6mo ago
I need to think about it. So a BackgroundService will run at the same time as the API is listening?
Pobiega
Pobiega6mo ago
yup.
Eple
EpleOP6mo ago
And it can run some code at program startup. I appreciate your help.
Pobiega
Pobiega6mo ago
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.
Eple
EpleOP6mo ago
I understand. Thanks for your assistance.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Eple
EpleOP6mo ago
I understand, @TeBeCo. Thanks for your response!
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Eple
EpleOP6mo ago
Okay, I'll make sure to test it.
Want results from more Discord servers?
Add your server