// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc( options => { options.Filters.Add(typeof(ErrorHandleMiddleware)); }); ServicesRegistrar.Configure(services, Configuration); RepositoryRegistrar.Configure(services, Configuration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); // Add application services. services.AddTransient <IEmailSender, EmailSender>(); services.AddMvc(); var servicesRegistrar = new ServicesRegistrar(); servicesRegistrar.RegisterServices(services); }
private void ConfigureServices(IServiceCollection services) { var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json"); Configuration = builder.Build(); var sqlConnectionString = Configuration["ConnectionString"]; // Register EntityFramework 7 services.AddIdentity <ApplicationUser, ApplicationRole>(config => { config.User.RequireUniqueEmail = true; config.Password = new PasswordOptions { RequireDigit = false, RequireNonAlphanumeric = false, RequireLowercase = false, RequireUppercase = false, RequiredLength = 8, }; }) .AddEntityFrameworkStores <ApplicationDbContext, string>() .AddDefaultTokenProviders(); services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql( sqlConnectionString )); // Register UserManager & RoleManager services.AddIdentity <ApplicationUser, ApplicationRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); // UserManager & RoleManager require logging and HttpContext dependencies services.AddLogging(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped(typeof(IRepository <>), typeof(Repository <>)); ServicesRegistrar.Register(services); HelperRegistrar.Register(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IConfiguration>(Configuration); // Use a PostgresSQL Database var sqlConnectionString = Configuration["DataAccessPostgreSqlProvider:ConnectionString"]; services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql( sqlConnectionString, b => b.MigrationsAssembly("App.Web") ) ); services.Configure <IdentityOptions>(options => { options.Tokens.EmailConfirmationTokenProvider = EmailConfirmationTokenProviderName; options.Tokens.PasswordResetTokenProvider = PasswordResetTokenProviderName; }); services.Configure <ConfirmEmailDataProtectionTokenProviderOptions>(options => { options.TokenLifespan = TimeSpan.FromHours(5); }); services.Configure <PasswordResetProtectionTokenProviderOptions>(options => { options.TokenLifespan = TimeSpan.FromMinutes(5); }); services.Configure <HostConfiguration>(HostConfiguration => { HostConfiguration.Name = Configuration["host:name"]; HostConfiguration.Protocol = Configuration["host:protocol"]; }); services.AddIdentity <ApplicationUser, ApplicationRole>(config => { config.User.RequireUniqueEmail = true; config.Password = new PasswordOptions { RequireDigit = false, RequireNonAlphanumeric = false, RequireLowercase = false, RequireUppercase = false, RequiredLength = 8, }; config.Cookies.ApplicationCookie.LoginPath = "/Account/Login"; }) .AddEntityFrameworkStores <ApplicationDbContext, string>() .AddDefaultTokenProviders() .AddTokenProvider <ConfirmEmailDataProtectorTokenProvider <ApplicationUser> >(EmailConfirmationTokenProviderName) .AddTokenProvider <PasswordResetDataProtectorTokenProvider <ApplicationUser> >(PasswordResetTokenProviderName); services.AddApplicationInsightsTelemetry(Configuration); services.Configure <IISOptions>(options => { options.AutomaticAuthentication = true; }); services.AddSession(); services.AddScoped <LogFilter>(); // Add framework services. services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; options.SerializerSettings.MaxDepth = 1; }); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); var dtTablesOptions = new DataTables.AspNet.AspNetCore.Options(10, true, true, true, new CamelCaseRequestNameConvention(), new CamelCaseResponseNameConvention()); services.RegisterDataTables(dtTablesOptions); MapperConfig.Map(services); services.AddScoped(typeof(IRepository <>), typeof(Repository <>)); services.AddScoped <LogFilter>(); ServicesRegistrar.Register(services); HelperRegistrar.Register(services); services.AddSingleton <ISmtpOptionsService, SmtpOptionsService>(x => new SmtpOptionsService() { User = "******", Password = "******", Server = "smtp.gmail.com", Port = 465, UseSsl = true, FromEmail = "*****@*****.**", FromName = "*****@*****.**", PrefferedEncoding = null, RequiresAunthetication = true }); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); services.AddIdentityServer() .AddTemporarySigningCredential() .AddInMemoryClients(IdSrvConfig.GetClients()) .AddInMemoryScopes(IdSrvConfig.GetScopes()) .AddAspNetIdentity <ApplicationUser>() .AddProfileService <IdentityWithAdditionalClaimsProfileService>(); services.AddCors(options => { options.AddPolicy("AllowSpecificOrigin", builder => builder.AllowAnyOrigin()); }); }