// Clean up the request
        public void DisposeContext(Context context, Exception?exception)
        {
            var httpContext = context.HttpContext !;

            _diagnostics.RequestEnd(httpContext, exception, context);

            if (_defaultHttpContextFactory != null)
            {
                _defaultHttpContextFactory.Dispose((DefaultHttpContext)httpContext);

                if (_defaultHttpContextFactory.HttpContextAccessor != null)
                {
                    // Clear the HttpContext if the accessor was used. It's likely that the lifetime extends
                    // past the end of the http request and we want to avoid changing the reference from under
                    // consumers.
                    context.HttpContext = null;
                }
            }
            else
            {
                _httpContextFactory !.Dispose(httpContext);
            }

            HostingApplicationDiagnostics.ContextDisposed(context);

            // Reset the context as it may be pooled
            context.Reset();
        }
Exemple #2
0
 public HostingApplication(
     RequestDelegate application,
     ILogger logger,
     DiagnosticListener diagnosticSource,
     IHttpContextFactory httpContextFactory)
 {
     _application        = application;
     _diagnostics        = new HostingApplicationDiagnostics(logger, diagnosticSource);
     _httpContextFactory = httpContextFactory;
 }
Exemple #3
0
 public HostingApplication(
     RequestDelegate application,
     ILogger logger,
     DiagnosticListener diagnosticSource,
     IHttpContextFactory httpContextFactory)
 {
     _application = application;
     _diagnostics = new HostingApplicationDiagnostics(logger, diagnosticSource);
     if (httpContextFactory is DefaultHttpContextFactory factory)
     {
         _defaultHttpContextFactory = factory;
     }
     else
     {
         _httpContextFactory = httpContextFactory;
     }
 }
 public HostingApplication(
     RequestDelegate application,
     ILogger logger,
     DiagnosticListener diagnosticSource,
     ActivitySource activitySource,
     DistributedContextPropagator propagator,
     IHttpContextFactory httpContextFactory)
 {
     _application = application;
     _diagnostics = new HostingApplicationDiagnostics(logger, diagnosticSource, activitySource, propagator);
     if (httpContextFactory is DefaultHttpContextFactory factory)
     {
         _defaultHttpContextFactory = factory;
     }
     else
     {
         _httpContextFactory = httpContextFactory;
     }
 }