I need to execute some logic after application startup in ASP Core app.
In ASP MVC it's performed in Application_Start() Global.asax method.
How am I supposed to do it in ASP Core (in respect with best practice) ?
1 Answer
you can use Configure method in Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
....
IMyEndpointService service = app.ApplicationServices.GetService<IMyEndpointService>();
var result = service.ExecuteMyMethod();
....
}
but it also depends on what you are trying to achieve. If you provide more information you can get to the point answer.