title: How to use dependency injection with .net core JwtBearerOptions.Events?
body: <p>.Net Core Api for <code>JwtBearer</code> looks like this:</p>
  
  <pre><code>_services
      .AddJwtBearer(options =&gt;
       {
          options.Events.OnAuthenticationFailed += MyMethod;
       });
  </code></pre>
  
  <p>It's literally just a function. Now I want to use an <code>ILogger</code> that I have in the services configuration for to be used while logging failed authentication request. The problem is that I don't have the instance of the <code>ILogger</code> at this point in time and I don't really see a good way of obtaining it or using a factory method either since I don't have <code>ServiceProvider</code> either.</p>
  
  <p>I have solved it like this:</p>
  
  <pre><code>var loggerForAuthentication = _services.BuildServiceProvider().GetService&lt;ILogger&gt;();
  </code></pre>
  
  <p>That will build the whole DI container to return my <code>ILogger</code>. There are some downsides with this approach like e.g. generating of it's own singletons for this exact service builder and does not look right as well.</p>
  
  <p>Is there any other way to do this?</p>