I have an ASP.NET MVC 5 app (.NET Framework 4.8), using OWIN.
The DI container is created in the startup and does it's job well in services and controllers. But I don't know of any way to resolve objects in the Application_Error
event.
Startup class:
[assembly: OwinStartup(typeof(MyWebsite.Startup))]
namespace MyWebsite
{
public class Startup {
public void Configuration(IAppBuilder app)
{
ServiceCollection services = new ServiceCollection();
...
ContainerBuilder builder = new ContainerBuilder();
builder.Populate(services);
builder.RegisterType<MyLogger>().As<ILogger>().InstancePerLifetimeScope();
...
}
}
Global.asax:
public void Application_Error(object sender, EventArgs e)
{
//How to get an ILogger instance here?
}
Edit: My logging has a dependency on other services, so I cannot manually instantiate the logging class. I really need a resolver for MyLogger