Most of the authentication middleware in ASP.NET Core follows the same pattern; it exposes an options object where you can register for multiple events:
But what if you want to use dependency injection inside an event handler? The moment the middleware is configured the IoC container is still in construction and is not accessible yet.
What you can do is, instead of directly registering an event handler for a specific event is to specify an event class using the EventsType property: