public static IHttpContextBuilder UseOwinEnvironment(
     this IHttpContextBuilder builder,
     Func <IServiceProvider, IDictionary <string, object> > environmentFactory,
     ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
 {
     return(builder.UseOwin(provider => new OwinContext(environmentFactory(provider)), serviceLifetime));
 }
 public static IHttpContextBuilder UseOwinFromHttpContext(
     this IHttpContextBuilder builder,
     Func <IServiceProvider, HttpContextBase> httpContextFactory,
     ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
 {
     return(builder.UseOwin(provider => httpContextFactory(provider).GetOwinContext(), serviceLifetime));
 }
        public static IHttpContextBuilder UseOwin(
            this IHttpContextBuilder builder,
            Func <IServiceProvider, IOwinContext> owinContextFactory,
            ServiceLifetime serviceLifetime = ServiceLifetime.Transient)
        {
            builder.Services.TryAdd(ServiceDescriptor.Describe(typeof(IOwinContext), owinContextFactory, serviceLifetime));

            builder.AddHttpContext <OwinHttpContextAccessor>(serviceLifetime);

            return(builder);
        }
 public static IHttpContextBuilder UseOwinFromCurrentHttpContext(this IHttpContextBuilder builder)
 {
     return(builder.UseOwinFromHttpContext(provider => new HttpContextWrapper(HttpContext.Current)));
 }
        /// <summary>
        /// Uses the default ASP.NET CORE <see cref="IHttpContextAccessor"/>. If it exists, no action is
        /// taken. If it does not exist then the <see cref="HttpContextAccessor"/> is added.
        /// </summary>
        /// <param name="builder"></param>
        public static IHttpContextBuilder UseDefaultAspNetCore(this IHttpContextBuilder builder)
        {
            builder.Services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            return(builder);
        }
        /// <summary>
        /// Uses the default ASP.NET CORE <see cref="IHttpContextAccessor"/>. If it exists, no action is
        /// taken. If it does not exist then a default implementation for the <see cref="IHttpContextAccessor"/> is added.
        /// </summary>
        /// <param name="builder"></param>
        public static IHttpContextBuilder UseDefaultAspNetCore(this IHttpContextBuilder builder)
        {
            builder.Services.AddHttpContextAccessor();

            return(builder);
        }