public static IServiceCollection ConfigureDataContext(this IServiceCollection services, IConfiguration configuration) { if (configuration == null) throw new Exception("sex1"); var runningOnMono = Type.GetType("Mono.Runtime") != null; var configInMemory = configuration["Data:UseInMemoryStore"] != null && configuration["Data:UseInMemoryStore"].Equals("true", StringComparison.OrdinalIgnoreCase); bool useInMemoryStore = runningOnMono || configInMemory; var connectionStrging = configuration["Data:DefaultConnection:ConnectionString"]; if (useInMemoryStore || string.IsNullOrEmpty(connectionStrging)) { services.AddEntityFrameworkInMemoryDatabase() .AddDbContext<MyShuttleContext>(options => { options.UseInMemoryDatabase(); }); } else { services.AddEntityFrameworkSqlServer() .AddDbContext<MyShuttleContext>(options => { options.UseSqlServer(connectionStrging); }); } return services; }
public static IServiceCollection AddCloudscribeCoreEFStorageMSSQL( this IServiceCollection services, string connectionString ) { services.AddCloudscribeCoreEFCommon(); services.AddEntityFrameworkSqlServer() .AddDbContext<CoreDbContext>((serviceProvider, options) => options.UseSqlServer(connectionString) .UseInternalServiceProvider(serviceProvider) ); services.AddScoped<ICoreDbContext, CoreDbContext>(); services.AddScoped<IDataPlatformInfo, DataPlatformInfo>(); return services; }
public static void ConfigureIdentityServerServices(this IServiceCollection services, string connectionString) { services .AddEntityFrameworkSqlServer() .AddDbContext<UserContext>(o => o.UseSqlServer(connectionString)) .AddDbContext<IdentityServerOperationalContext>(o => o.UseSqlServer(connectionString)) .AddIdentity<User, IdentityRole>() .AddEntityFrameworkStores<UserContext>() .AddDefaultTokenProviders(); var identity = services .AddIdentityServer(o => o.RequireSsl = false) .AddInMemoryClients(Clients) .AddInMemoryScopes(Scopes); identity.SetSigningCredential(IdentityServerSigning.SecurityKey); identity.ConfigureEntityFramework().RegisterOperationalStores<IdentityServerOperationalContext>(); services.AddMvc(); identity.Services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>(); identity.Services.AddTransient<IProfileService, ProfileService>(); }
//public static IIdentityServerBuilder AddOperationalStoreMSSQL( // this IIdentityServerBuilder builder, // string connectionString, // Action<DbContextOptionsBuilder> optionsAction = null) //{ // builder.Services.AddEntityFrameworkSqlServer() // .AddDbContext<PersistedGrantDbContext>((serviceProvider, options) => // options.UseSqlServer(connectionString) // .UseInternalServiceProvider(serviceProvider) // ); // builder.Services.AddScoped<IPersistedGrantDbContext, PersistedGrantDbContext>(); // return builder; //} public static IServiceCollection AddCloudscribeCoreIdentityServerEFStorageMSSQL( this IServiceCollection services, string connectionString ) { services.AddEntityFrameworkSqlServer() .AddDbContext<ConfigurationDbContext>((serviceProvider, options) => options.UseSqlServer(connectionString) .UseInternalServiceProvider(serviceProvider) ); services.AddCloudscribeCoreIdentityServerStores(); services.AddScoped<IConfigurationDbContext, ConfigurationDbContext>(); services.AddEntityFrameworkSqlServer() .AddDbContext<PersistedGrantDbContext>((serviceProvider, options) => options.UseSqlServer(connectionString) .UseInternalServiceProvider(serviceProvider) ); services.AddScoped<IPersistedGrantDbContext, PersistedGrantDbContext>(); return services; }