Run code once the application starts in .Net6
Maybe you need to execute some code once the application starts. Like log something, if you are a developer, you may need to populate some data in memory, run background tasks, publish an event, or read configuration.
The first thing you probably have in mind is to write code in the Program.cs file. The .Net6 ensures that these methods, and therefore the code placed in them, will only be executed when the application starts.
The developer can run code in two ways, between the builder.Services(…) here…