public void ConfigureServices(IServiceCollection services) { services .Configure <ApiClientConfiguration>(BindApiClientConfiguration) .AddTransient <Interop>() .AddSingleton <PwaInstallInterop>() .AddTransient <NetworkStateInterop>() .AddSingleton <NetworkState>() .AddTransient <CurrencyStorage>() .AddTransient <CategoryStorage>() .AddTransient <ProfileStorage>() .AddTransient <NavigatorUrl>() .AddSingleton <Navigator>() .AddSingleton <ApiClient>() .AddSingleton <ModalInterop>() .AddSingleton <TokenContainer>() .AddSingleton <QueryString>() .AddSingleton <CommandMapper>() .AddSingleton <QueryMapper>() .AddSingleton <ColorCollection>() .AddSingleton <IconCollection>(); bootstrapTask = new Bootstrap.BootstrapTask(services); bootstrapTask.Initialize(); }
public void ConfigureServices(IServiceCollection services) { services .AddTransient <ApiClient>() .AddSingleton <ColorCollection>() .AddSingleton <IconCollection>(); Bootstrap.BootstrapTask bootstrapTask = new Bootstrap.BootstrapTask(services); bootstrapTask.Initialize(); }
public void ConfigureServices(IServiceCollection services) { services .AddTransient <Navigator>() .AddTransient <ApiClient>() .AddSingleton <Native>() .AddSingleton <TokenContainer>() .AddSingleton <QueryString>() .AddSingleton <CommandMapper>() .AddSingleton <QueryMapper>() .AddSingleton <ColorCollection>() .AddSingleton <IconCollection>(); Bootstrap.BootstrapTask bootstrapTask = new Bootstrap.BootstrapTask(services); bootstrapTask.Initialize(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionStrings = Configuration.GetSection("ConnectionStrings").Get <Bootstrap.ConnectionStrings>(); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlite(connectionStrings.Application) ); services.AddResponseCompression(options => { options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { MediaTypeNames.Application.Octet, WasmMediaTypeNames.Application.Wasm, }); }); services.AddAuthentication().AddCookie(); services.AddAuthorization(options => { options.AddPolicy("Api", policy => { policy.AuthenticationSchemes.Add(CookieAuthenticationDefaults.AuthenticationScheme); policy.RequireAuthenticatedUser(); }); }); services.AddIdentity <ApplicationUser, IdentityRole>(options => Configuration.GetSection("Identity").GetSection("Password").Bind(options.Password)) .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddRouting(options => options.LowercaseUrls = true); services.AddMvc(); services.AddSignalR(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <ApiHub>(); Bootstrap.BootstrapTask bootstrapTask = new Bootstrap.BootstrapTask(services, connectionStrings); bootstrapTask.Initialize(); }
public void ConfigureServices(IServiceCollection services) { ConnectionStrings connectionStrings = Configuration .GetSection("ConnectionStrings") .Get <ConnectionStrings>(); string ApplyBasePath(string value) => value.Replace("{BasePath}", Environment.ContentRootPath); connectionStrings.Application = ApplyBasePath(connectionStrings.Application); connectionStrings.EventSourcing = ApplyBasePath(connectionStrings.EventSourcing); connectionStrings.ReadModel = ApplyBasePath(connectionStrings.ReadModel); services .AddDbContext <ApplicationDbContext>(options => options.UseSqlite(connectionStrings.Application)); services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { JwtOptions configuration = Configuration.GetSection("Jwt").Get <JwtOptions>(); options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = configuration.Issuer, ValidAudience = configuration.Issuer, IssuerSigningKey = configuration.GetSecurityKey() }; options.Events = new JwtBearerEvents { OnMessageReceived = context => { var path = context.HttpContext.Request.Path; if (path.StartsWithSegments("/api")) { var accessToken = context.HttpContext.Request.Query["access_token"]; if (!string.IsNullOrEmpty(accessToken)) { context.Token = accessToken; } } return(Task.CompletedTask); } }; options.SaveToken = true; }); services .AddAuthorization(options => { options.DefaultPolicy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build(); }); services .AddIdentityCore <ApplicationUser>(options => Configuration.GetSection("Identity").GetSection("Password").Bind(options.Password)) .AddEntityFrameworkStores <ApplicationDbContext>(); services .AddRouting(options => options.LowercaseUrls = true) .AddControllers() .AddNewtonsoftJson(); services .AddSignalR(); services .AddHealthChecks() .AddDbContextCheck <ApplicationDbContext>() .AddFactoryDbContextCheck <ReadModelContext>() .AddFactoryDbContextCheck <EventSourcingContext>(); services .AddTransient <JwtSecurityTokenHandler>() .Configure <JwtOptions>(Configuration.GetSection("Jwt")); services .AddSingleton <Json>() .AddSingleton <IHttpContextAccessor, HttpContextAccessor>() .AddSingleton <IUserIdProvider>(new DefaultUserIdProvider()) .AddTransient <ExceptionMiddleware>() .AddSingleton <ApiHub>() .AddSingleton <CommandMapper>() .AddSingleton <QueryMapper>(); Bootstrap.BootstrapTask bootstrapTask = new Bootstrap.BootstrapTask(services, connectionStrings); bootstrapTask.Initialize(); }
public void ConfigureServices(IServiceCollection services) { IConfiguration connectionStrings = Configuration.GetSection("Database"); services .AddDbContextWithSchema <AccountContext>(connectionStrings.GetSection("Application"), ApplyBasePath); services .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { JwtOptions configuration = Configuration.GetSection("Jwt").Get <JwtOptions>(); options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = configuration.Issuer, ValidAudience = configuration.Issuer, IssuerSigningKey = configuration.GetSecurityKey() }; options.Events = new JwtBearerEvents { OnMessageReceived = context => { var path = context.HttpContext.Request.Path; if (path.StartsWithSegments("/api")) { string accessToken = context.HttpContext.Request.Query["access_token"].FirstOrDefault(); if (!string.IsNullOrEmpty(accessToken)) { context.Token = accessToken; } } return(Task.CompletedTask); } }; options.SaveToken = true; }); services .AddAuthorization(options => { options.DefaultPolicy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser() .Build(); }); services .AddIdentityCore <User>(options => Configuration.GetSection("Identity").GetSection("Password").Bind(options.Password)) .AddEntityFrameworkStores <AccountContext>(); services .AddRouting(options => options.LowercaseUrls = true) .AddControllers() .AddNewtonsoftJson(); services .AddVersionHeader(); services .AddSignalR(); services .AddHealthChecks() .AddDbContextCheck <AccountContext>() .AddFactoryDbContextCheck <ReadModelContext>() .AddFactoryDbContextCheck <EventSourcingContext>(); services .AddTransient <JwtTokenGenerator>() .AddTransient <JwtSecurityTokenHandler>() .Configure <JwtOptions>(Configuration.GetSection("Jwt")); services .AddSingleton <Json>() .AddSingleton <IHttpContextAccessor, HttpContextAccessor>() .AddSingleton <IUserIdProvider>(new DefaultUserIdProvider()) .AddTransient <ExceptionMiddleware>() .AddTransient <RenewableTokenMiddleware>() .AddSingleton <ApiHub>() .AddSingleton <CommandMapper>() .AddSingleton <QueryMapper>(); var allowedUserPropertyKeys = Configuration.GetSection("UserProperties").Get <string[]>() ?? new string[0]; Bootstrap.BootstrapTask bootstrapTask = new Bootstrap.BootstrapTask(services, connectionStrings, allowedUserPropertyKeys, ApplyBasePath); bootstrapTask.Initialize(); }