// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); var connectionString = Configuration.GetConnectionString("ServiceDb"); var userDbConnString = Configuration.GetConnectionString("UserDb"); var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; services.Configure <ApplicationSettings>(Configuration.GetSection("ApplicationSettings")); services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings")); services.AddOptions(); services.AddSingleton <IServiceConfigurationAgent, ServiceConfiguration>(); services.AddTransient <IVerificationProxy, VerificationProxy>(); services.AddTransient <IWechatProxy, WechatProxy>(); services.AddTransient <IPaymentServiceProxy, PaymentServiceProxy>(); services.AddTransient <IUserServiceProxy, UserServiceProxy>(); services.AddTransient <IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); services.AddTransient <PartnerAuthCodeValidator>(); services.AddTransient <VerifyCodeValidator>(); services.AddTransient <WechatAppletValidator>(); services.AddScoped <IDbUnitOfWork, DbUnitOfWork>(); services.AddScoped <IDbContextProvider, DbContextProvider>(); services.AddDbContext <ConfigurationCustomDbContext>(options => options.UseMySql(connectionString)); services.AddDbContext <PersistedGrantCustomDbContext>(options => options.UseMySql(connectionString)); services.AddIdentityServer() .AddSigningCredential(new X509Certificate2(@"./certificate/gooios.pfx", "!QAZ2wsx098", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable)) .AddTestUsers(DataConfiguration.GetUsers().ToList()) .AddConfigurationStore <ConfigurationCustomDbContext>(options => { options.ConfigureDbContext = builder => builder.UseMySql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); }) .AddOperationalStore <PersistedGrantCustomDbContext>(options => { options.ConfigureDbContext = builder => builder.UseMySql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); options.EnableTokenCleanup = true; options.TokenCleanupInterval = 7200; }) .AddResourceOwnerValidator <ResourceOwnerPasswordValidator>() .AddExtensionGrantValidator <VerifyCodeValidator>() .AddExtensionGrantValidator <PartnerAuthCodeValidator>() .AddExtensionGrantValidator <WechatAppletValidator>() .AddProfileService <ProfileService>(); services.ConfigureDynamicProxy(config => { config.Interceptors.AddTyped <ExceptionInterceptor>(m => m.DeclaringType.Name.EndsWith("AppService")); //config.Interceptors.AddTyped<TransactionInterceptor>(m => m.DeclaringType.Name.EndsWith("AppService")); config.Interceptors.AddTyped <ProxyInterceptor>(m => m.DeclaringType.Name.EndsWith("Proxy")); }); }