public static void ConfigureDbContext(this IServiceCollection services, ConnectionStringsOptions connectionStringsOptions) { services .AddDbContext <AdminAppContext>(opts => opts .UseSqlServer(connectionStringsOptions.DefaultConnection, b => { b.EnableRetryOnFailure(3); b.MigrationsAssembly("AdminApp.Data"); }) .UseLoggerFactory(DebugLoggerFactory) .EnableSensitiveDataLogging()) //.AddScoped(_ => new AdminAppContext(connectionStringsOptions.DefaultConnection)) ; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(opt => { opt.AddPolicy("AppPolicy", builder => { builder .WithOrigins("http://localhost:3000") .AllowAnyMethod() .AllowAnyHeader() .WithExposedHeaders("Content-Disposition", "x-suggested-filename"); }); }); services.AddTransient <IInvoiceService, InvoiceService>(); services.AddSingleton <IEmailSender, EmailSender>(); services.AddAutoMapper(typeof(Startup)); services.Configure <ConnectionStringsOptions>(Configuration .GetSection("ConnectionString")); services.Configure <InvoicesOptions>(Configuration .GetSection("Invoices")); services.Configure <AuthOptions>(Configuration .GetSection("Auth")); services.Configure <SmtpOptions>(Configuration .GetSection("SmtpOptions")); IConfigurationSection connectionSection = Configuration.GetSection("ConnectionStrings"); var connectionStringOptions = new ConnectionStringsOptions(); connectionSection.Bind(connectionStringOptions); IConfigurationSection authSection = Configuration.GetSection("Auth"); var authOptions = new AuthOptions(); authSection.Bind(authOptions); services.AddDbContextPool <InvoiceDbContext>(opt => opt .UseSqlServer(connectionStringOptions.DefaultConnection)); services.AddIdentity <IdentityUser, IdentityRole>() .AddEntityFrameworkStores <InvoiceDbContext>() .AddDefaultTokenProviders(); services.AddAuthentication(opt => { opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; opt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(opt => { opt.SaveToken = true; opt.RequireHttpsMetadata = false; var secretByte = Encoding.UTF8.GetBytes(authOptions.Secret); var key = new SymmetricSecurityKey(secretByte); opt.TokenValidationParameters = new TokenValidationParameters() { ValidIssuer = authOptions.Issuer, ValidAudience = authOptions.Audience, IssuerSigningKey = key, ClockSkew = TimeSpan.Zero }; }); services.Configure <DataProtectionTokenProviderOptions>(opt => { opt.TokenLifespan = TimeSpan.FromHours(1); }); services .AddControllers() .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>()) .AddNewtonsoftJson(); }
public StatusRepository(IOptions <ConnectionStringsOptions> connectionStringsOptions) { this.connectionStringsOptions = connectionStringsOptions.Value; }
public LocationController(Func <ISpecialService> serviceFunc, IOptions <ConnectionStringsOptions> options) { this.serviceFunc = serviceFunc; this.options = options.Value; }
public MoviesController(ApplicationDbContext context, IOptions <ConnectionStringsOptions> connectionStringOptions) { _context = context; _connectionStringOptions = connectionStringOptions.Value; }
public FilesServices(IOptions <ConnectionStringsOptions> connectionStringsOptions, ILogger <FilesServices> logger) { _connectionStringsOptions = connectionStringsOptions.Value; _logger = logger; }
public OptionsPatternController(IOptions <EntityFrameworkOptions> entityFrameworkOptions, IOptions <ConnectionStringsOptions> connectionStringsOptions) { _entityFrameworkOptions = entityFrameworkOptions.Value; _connectionStringsOptions = connectionStringsOptions.Value; }
public WeatherService(IHttpClientFactory clientFactory, IOptions <ConnectionStringsOptions> options) { this.clientFactory = clientFactory; this.options = options.Value; }