public void ConfigureServices(IServiceCollection services) { // Get Configuration services.ConfigureRootConfiguration(Configuration); var rootConfiguration = services.BuildServiceProvider().GetService <IRootConfiguration>(); ///// Manual configuration //services // .AddCustomConfiguration // <AdminIdentityDbContext, IdentityServerConfigurationDbContext, IdentityServerPersistedGrantDbContext, AdminLogDbContext> // (HostingEnvironment, // StartupHelpers.DefaultIdentityDbContextOptions(Configuration), // StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration), // StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration), // StartupHelpers.DefaultLogDbContextOptions(Configuration)) // .AddCustomIdentity // <AdminIdentityDbContext, UserIdentity, UserIdentityRole> // (StartupHelpers.DefaultIdentityOptions(Configuration)) // .AddCustomAdminAspNetIdentityServices // <AdminIdentityDbContext, IdentityServerPersistedGrantDbContext, UserDto<string>, string, RoleDto<string>, string, string, string, // UserIdentity, UserIdentityRole, string, UserIdentityUserClaim, UserIdentityUserRole, // UserIdentityUserLogin, UserIdentityRoleClaim, UserIdentityUserToken, // UsersDto<UserDto<string>, string>, RolesDto<RoleDto<string>, string>, UserRolesDto<RoleDto<string>, string, string>, // UserClaimsDto<string>, UserProviderDto<string>, UserProvidersDto<string>, UserChangePasswordDto<string>, // RoleClaimsDto<string>, UserClaimDto<string>, RoleClaimDto<string>>(); ///// Single tenant configuration (default) services.AddSingleTenantConfiguration(HostingEnvironment, StartupHelpers.DefaultIdentityDbContextOptions(Configuration), StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration), StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration), StartupHelpers.DefaultLogDbContextOptions(Configuration), StartupHelpers.DefaultIdentityOptions(Configuration)); /// Multi Tenant configuration //services.AddMultiTenantConfiguration(HostingEnvironment, // StartupHelpers.DefaultIdentityDbContextOptions(Configuration), // StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration), // StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration), // StartupHelpers.DefaultLogDbContextOptions(Configuration), // StartupHelpers.DefaultIdentityOptions(Configuration)); // Add Asp.Net Core Identity Configuration and OpenIdConnect auth as well services.AddAuthenticationServices(HostingEnvironment, rootConfiguration.AdminConfiguration); // Add exception filters in MVC services.AddMvcExceptionFilters(); // Add authorization policies for MVC services.AddAuthorizationPolicies(); services.Configure <SeedData>(Configuration.GetSection(ConfigurationConsts.SeedDataConfigurationKey)); }
public void ConfigureServices(IServiceCollection services) { var adminApiConfiguration = Configuration.GetSection(nameof(AdminApiConfiguration)).Get <AdminApiConfiguration>(); services.AddSingleton(adminApiConfiguration); ///// Single Tenant configuration services.AddSingleTenantConfiguration(HostingEnvironment, StartupHelpers.DefaultIdentityDbContextOptions(Configuration), StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration), StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration), StartupHelpers.DefaultLogDbContextOptions(Configuration), StartupHelpers.DefaultIdentityOptions(Configuration)); /// Multi Tenant configuration //services.AddMultiTenantConfiguration(HostingEnvironment, // StartupHelpers.DefaultIdentityDbContextOptions(Configuration), // StartupHelpers.DefaultIdentityServerConfigurationOptions(Configuration), // StartupHelpers.DefaultIdentityServerOperationalStoreOptions(Configuration), // StartupHelpers.DefaultLogDbContextOptions(Configuration), // StartupHelpers.DefaultIdentityOptions(Configuration)); //services.AddDbContexts<AdminIdentityDbContext, IdentityServerConfigurationDbContext, IdentityServerPersistedGrantDbContext, AdminLogDbContext>(Configuration); services.AddScoped <ControllerExceptionFilterAttribute>(); services.AddApiAuthentication(adminApiConfiguration); services.AddAuthorizationPolicies(); services.AddSwaggerGen(options => { options.SwaggerDoc(ApiConfigurationConsts.ApiVersionV1, new Info { Title = ApiConfigurationConsts.ApiName, Version = ApiConfigurationConsts.ApiVersionV1 }); options.AddSecurityDefinition("oauth2", new OAuth2Scheme { Flow = "implicit", AuthorizationUrl = $"{adminApiConfiguration.IdentityServerBaseUrl}/connect/authorize", Scopes = new Dictionary <string, string> { { adminApiConfiguration.OidcApiName, ApiConfigurationConsts.ApiName } } }); options.OperationFilter <AuthorizeCheckOperationFilter>(); }); }