private static void SeedTestData(IServiceProviderAccessor context)
 {
     using var scope = context.ServiceProvider.CreateScope();
     AsyncHelper.RunSync(() => scope.ServiceProvider
                         .GetRequiredService <AbpIdentityServerTestDataBuilder>()
                         .BuildAsync());
 }
Ejemplo n.º 2
0
        private static Func <object> BuildScopedInstanceCreator(
            Type serviceType, IServiceProviderAccessor accessor)
        {
            // The ServiceProviderAccessor allows access to a request-specific IServiceProvider. This
            // allows Scoped and Transient instances to be resolved from a scope instead of the root
            // container—resolving them from the root container will cause memory leaks. Specific
            // framework integration (such as Simple Injector's ASP.NET Core integration) can override
            // this accessor with one that allows retrieving the IServiceProvider from a web request.
            return(() =>
            {
                IServiceProvider current;

                try
                {
                    current = accessor.Current;
                }
                catch (ActivationException ex)
                {
                    // The DefaultServiceProviderAccessor will throw an ActivationException in case the
                    // IServiceProvider (or in fact the underlying IServiceScope) is requested outside the
                    // context of an active scope. Here we enrich that exception message with information
                    // of the actual requested cross-wired service.
                    throw new ActivationException(
                        $"Error resolving the cross-wired {serviceType.ToFriendlyName()}. {ex.Message}", ex);
                }

                return current.GetRequiredService(serviceType);
            });
        }
Ejemplo n.º 3
0
 internal SimpleInjectorAddOptions(
     IServiceCollection services, Container container, IServiceProviderAccessor accessor)
 {
     this.Services  = services;
     this.Container = container;
     this.serviceProviderAccessor = accessor;
 }
 internal AspNetCoreServiceProviderAccessor(
     IHttpContextAccessor accessor,
     IServiceProviderAccessor decoratee)
 {
     this.decoratee = decoratee;
     this.accessor  = accessor;
 }
Ejemplo n.º 5
0
 internal OnePerRequestServiceProviderAccessor(
     IHttpContextAccessor accessor,
     IServiceProviderAccessor decoratee)
 {
     this.decoratee = decoratee;
     this.accessor  = accessor;
 }
        private static void RegisterPaymentMethods(IServiceProviderAccessor context)
        {
            var resolver = context.ServiceProvider.GetService <IPaymentServiceResolver>();

            resolver.TryRegisterProvider(FreePaymentServiceProvider.PaymentMethod, typeof(FreePaymentServiceProvider));
            resolver.TryRegisterProvider(PrepaymentPaymentServiceProvider.PaymentMethod, typeof(PrepaymentPaymentServiceProvider));
            resolver.TryRegisterProvider(WeChatPayPaymentServiceProvider.PaymentMethod, typeof(WeChatPayPaymentServiceProvider));
        }
Ejemplo n.º 7
0
        public static void SetAccessor(IServiceProviderAccessor serviceProviderAccessor)
        {
            ServiceProviderAccessor = serviceProviderAccessor;

            if (Configuration == null)
            {
                Configuration = GetService <IConfiguration>();
            }
        }
        /// <summary>Constructs a new instance of <see cref="HttpContextScopeHttpModule"/>. This constructor is invoked by the ASP.NET runtime which uses the <see cref="HttpRuntime.WebObjectActivator"/> to provide the constructor parameters.</summary>
        public HttpContextScopeHttpModule(IServiceProviderAccessor rootServiceProviderAccessor)
        {
            if (rootServiceProviderAccessor == null)
            {
                throw new ArgumentNullException(nameof(rootServiceProviderAccessor));
            }

            this.config = rootServiceProviderAccessor.Configuration ?? throw new ArgumentException(message: "The " + nameof(rootServiceProviderAccessor.Configuration) + " property returned null.", paramName: nameof(rootServiceProviderAccessor));
            this.rootServiceProvider = rootServiceProviderAccessor.RootServiceProvider ?? throw new ArgumentException(message: "The " + nameof(rootServiceProviderAccessor.RootServiceProvider) + " property returned null.", paramName: nameof(rootServiceProviderAccessor));
        }
 private static Func <object> BuildScopedInstanceCreator(
     Type serviceType, IServiceProviderAccessor accessor)
 {
     // The ServiceProviderAccessor allows access to a request-specific IServiceProvider. This
     // allows Scoped and Transient instances to be resolved from a scope instead of the root
     // container—resolving them from the root container will cause memory leaks. Specific
     // framework integration (such as Simple Injector's ASP.NET Core integration) can override
     // this accessor with one that allows retrieving the IServiceProvider from a web request.
     return(() => accessor.Current.GetRequiredService(serviceType));
 }
Ejemplo n.º 10
0
 public static HttpContext GetHttpContext(this IServiceProviderAccessor serviceProviderAccessor)
 {
     return(serviceProviderAccessor.ServiceProvider.GetRequiredService <IHttpContextAccessor>().HttpContext);
 }
Ejemplo n.º 11
0
 internal OnePerNestedScopeServiceProviderAccessor(Container container, IServiceProviderAccessor decoratee)
 {
     this.decoratee = decoratee;
     this.container = container;
 }
        private readonly ConcurrentDictionary <Type, ObjectFactory> objectFactories = new ConcurrentDictionary <Type, ObjectFactory>();     // `ObjectFactory` is a delegate, btw.

        /// <summary>Constructor.</summary>
        public ObjectFactoryCache(IDependencyInjectionOverrideService serviceProviderOverrides, IServiceProviderAccessor serviceProviderAccessor)
        {
            this.serviceProviderOverrides = serviceProviderOverrides ?? throw new ArgumentNullException(nameof(serviceProviderOverrides));
            this.serviceProviderAccessor  = serviceProviderAccessor ?? throw new ArgumentNullException(nameof(serviceProviderAccessor));
        }