private void ContainerConfiguration(IServiceCollection services)
        {
            new Business.LayerServicesTypes()
            .GetServices()
            .GroupBy(s => s.Lifetime)
            .ToList()
            .ForEach(g =>
            {
                if (g.Key == CoreLib.TypeLifetime.Transient)
                {
                    g.ToList().ForEach(s =>
                    {
                        if (s.Implement != null)
                        {
                            services.AddTransient(s.BaseType, s.Implement);
                        }
                        else
                        {
                            services.AddTransient(s.BaseType, s.ImplementationType);
                        }
                    });
                }

                else if (g.Key == CoreLib.TypeLifetime.Scoped)
                {
                    g.ToList().ForEach(s =>
                    {
                        if (s.Implement != null)
                        {
                            services.AddScoped(s.BaseType, s.Implement);
                        }
                        else
                        {
                            services.AddScoped(s.BaseType, s.ImplementationType);
                        }
                    });
                }

                else if (g.Key == CoreLib.TypeLifetime.Singleton)
                {
                    g.ToList().ForEach(s =>
                    {
                        if (s.Implement != null)
                        {
                            services.AddSingleton(s.BaseType, s.Implement);
                        }
                        else if (s.Instance != null && s.BaseType != null)
                        {
                            services.AddSingleton(s.BaseType, s.Instance);
                        }
                        else if (s.Instance != null && s.BaseType == null)
                        {
                            services.AddSingleton(s.Instance);
                        }
                        else if (s.BaseType == null)
                        {
                            services.AddSingleton(s.ImplementationType);
                        }
                        else
                        {
                            services.AddSingleton(s.BaseType, s.ImplementationType);
                        }
                    });
                }
            });

            var setting = new CoreLib.AppSettings
            {
                ConnectionString  = Configuration["ConnectionString"],
                JwtSecret         = Configuration["Jwt:Secret"],
                JwtIssuer         = Configuration["Jwt:Issuer"],
                JwtRefreshPeriod  = int.Parse(Configuration["Jwt:RefreshPeriod"]),
                SmsApiAddress     = Configuration["Sms:ApiAddress"],
                SmsUsername       = Configuration["Sms:Username"],
                SmsPassword       = Configuration["Sms:Password"],
                SmsSender         = Configuration["Sms:Sender"],
                MembershipService = new Service
                {
                    Host   = Configuration["Services:Membership:Host"],
                    ApiKey = Configuration["Services:Membership:ApiKey"]
                },
                CoreService = new Service
                {
                    Host   = Configuration["Services:Core:Host"],
                    ApiKey = Configuration["Services:Core:ApiKey"]
                }
            };

            services.AddSingleton(typeof(CoreLib.IAppSettings), setting);

            services.AddHttpContextAccessor();

            services.AddDbContextPool <ErpCoreDBContext>((serviceProvider, options) =>
            {
                options.UseSqlServer(this.Configuration["ConnectionString"]);
                options.UseInternalServiceProvider(serviceProvider);
            }, 256);
            services.AddEntityFrameworkSqlServer();

            services.AddScoped <IMembershipServiceApi, MembershipServiceApi>();
            services.AddHostedService <QuartzHostedService>();
            services.AddTransient <CoreSmtpClient>();
            services.AddTransient <SmsHttpClient>();
            services.AddTransient <PaypalHttpClient>();
            services.AddTransient <DocusignHttpClient>();
            services.AddTransient <PlaceApi>();
            services.AddTransient <Captcha>();

            EstablishServicesHttpClients(services, setting);

            LoadStatistics(services.BuildServiceProvider());

            Thread.Sleep(10000);
            EstablishDbHttpClients(services);
        }
示例#2
0
        private void ContainerConfiguration(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            var appSetting = new CoreLib.AppSettings
            {
                ConnectionString  = Configuration["ConnectionString"],
                JwtSecret         = Configuration["Jwt:Secret"],
                JwtIssuer         = Configuration["Jwt:Issuer"],
                JwtValidDuration  = int.Parse(Configuration["Jwt:ValidDuration"]),
                SmsApiAddress     = Configuration["Sms:ApiAddress"],
                SmsUsername       = Configuration["Sms:Username"],
                SmsPassword       = Configuration["Sms:Password"],
                SmsSender         = Configuration["Sms:Sender"],
                MembershipService = new Service
                {
                    Host   = Configuration["Services:Membership:Host"],
                    ApiKey = Configuration["Services:Membership:ApiKey"]
                },
                CoreService = new Service
                {
                    Host   = Configuration["Services:Core:Host"],
                    ApiKey = Configuration["Services:Core:ApiKey"]
                },
                VerifyCodeValidMinutes = int.Parse(Configuration["VerifyCode:ValidMinutes"]),
                JwtRefreshPeriod       = int.Parse(Configuration["Jwt:RefreshPeriod"])
            };

            new Business.LayerServicesTypes()
            .GetServices()
            .GroupBy(s => s.Lifetime)
            .ToList()
            .ForEach(g =>
            {
                if (g.Key == CoreLib.TypeLifetime.Transient)
                {
                    g.ToList().ForEach(s =>
                    {
                        if (s.Implement != null)
                        {
                            services.AddTransient(s.BaseType, s.Implement);
                        }
                        else
                        {
                            services.AddTransient(s.BaseType, s.ImplementationType);
                        }
                    });
                }

                else if (g.Key == CoreLib.TypeLifetime.Scoped)
                {
                    g.ToList().ForEach(s =>
                    {
                        if (s.Implement != null)
                        {
                            services.AddScoped(s.BaseType, s.Implement);
                        }
                        else
                        {
                            services.AddScoped(s.BaseType, s.ImplementationType);
                        }
                    });
                }

                else if (g.Key == CoreLib.TypeLifetime.Singleton)
                {
                    g.ToList().ForEach(s =>
                    {
                        if (s.Implement != null)
                        {
                            services.AddSingleton(s.BaseType, s.Implement);
                        }
                        else if (s.Instance != null && s.BaseType != null)
                        {
                            services.AddSingleton(s.BaseType, s.Instance);
                        }
                        else if (s.Instance != null && s.BaseType == null)
                        {
                            services.AddSingleton(s.Instance);
                        }
                        else if (s.BaseType == null)
                        {
                            services.AddSingleton(s.ImplementationType);
                        }
                        else
                        {
                            services.AddSingleton(s.BaseType, s.ImplementationType);
                        }
                    });
                }
            });

            services.AddSingleton(typeof(CoreLib.IAppSettings), appSetting);
            services.AddHttpClient <CoreLib.HttpClients.SmsApiClient>(cf =>
                                                                      cf.BaseAddress = new Uri(appSetting.SmsApiAddress));
            services.AddSingleton <CoreLib.HttpClients.HttpClientFactory>();
            services.AddScoped <ICoreServiceApi, CoreServiceApi>();


            services.AddDbContextPool <ErpMembershipDBContext>((serviceProvider, options) =>
            {
                options.UseSqlServer(this.Configuration["ConnectionString"]);
                options.UseInternalServiceProvider(serviceProvider);
            }, 256);
            services.AddEntityFrameworkSqlServer();

            EstablishServicesHttpClients(services, appSetting);
        }