In Asp.net core, inside the Startup class, I configured a class AccountService as an injection inside this method:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddScoped(typeof(CharacterService));
}
I can successfully inject it on another class, but I want to also access CharacterService inside the Configure() method of Startup, because I want to call a method on the event of shut down of the server. Is it possible?
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime)
{
...
// var temp = app.ApplicationServices.GetService<CharacterService>();
hostApplicationLifetime.ApplicationStopping.Register(() =>
{
//CharacterService.Instance.SaveMemoryInDatabase();
});
}
How can I access CharacterService inside the Configure method?
Thanks,