Geek Culture
Published in

Geek Culture

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…

--

--

A new tech publication by Start it up (https://medium.com/swlh).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store