示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var conn      = Configuration.GetConnectionString("DefaultConnection");
            var userStore = new UserStore(conn);
            var roleStore = new RoleStore(conn);
            var manager   = new ApplicationPartManager();

            manager.ApplicationParts.Add(new AssemblyPart(typeof(Startup).Assembly));
            services.AddSingleton(manager);
            services.AddSingleton <IUserStore <ApplicationUser> >(userStore);
            services.AddSingleton <IRoleStore <ApplicationRole> >(roleStore);

            services.AddMvcCore();
            // Add framework services.
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDbContext <MardisContext>(options =>
                                                  options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            var sessionTimeOut = Configuration.GetValue <int>("SessionTimeOut");

            services.AddIdentity <ApplicationUser, ApplicationRole>(config =>
            {
                config.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromMinutes(sessionTimeOut);
                config.Lockout = new LockoutOptions()
                {
                    DefaultLockoutTimeSpan = TimeSpan.FromHours(2)
                };
            })
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings
                options.Password.RequireDigit           = true;
                options.Password.RequiredLength         = 8;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = true;
                options.Password.RequireLowercase       = false;
                //options.SecurityStampValidationInterval = new TimeSpan(1, 12, 23, 62);
                options.SecurityStampValidationInterval = TimeSpan.FromMinutes(sessionTimeOut);
                // Cookie settings
                options.Cookies.ApplicationCookie.LoginPath  = "/Account/Login";
                options.Cookies.ApplicationCookie.LogoutPath = "/Account/Login";

                // User settings
                options.User.RequireUniqueEmail = true;

                //services.AddCors();
            });


            services.Configure <FormOptions>(x => x.ValueCountLimit = 8192);

            services.AddDataProtection()
            .SetApplicationName("M@rdisEngin3")
            .SetDefaultKeyLifetime(TimeSpan.FromDays(14));

            services.AddCors(o => o.AddPolicy("MPT", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));

            // Add framework services.
            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver      = new DefaultContractResolver();
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            }
                            );
            services.Configure <MvcOptions>(options =>
            {
                options.Filters.Add(new CorsAuthorizationFilterFactory("MPT"));
            });
            services.AddDistributedMemoryCache();

            services.AddMemoryCache();
            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
            });



            services.AddSingleton <RedisCache, RedisCache>();

            //Add context to controllers
            services.AddDbContext <MardisContext>(opc => opc.UseSqlServer(conn));

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // Add application services.
            services.AddTransient <IEmailSender, AuthMessageSender>();
            services.AddTransient <ISmsSender, AuthMessageSender>();

            services.AddScoped <IMenuService, MenuService>();


            //.WithOrigins("https://localhost:44306")));
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var conn      = Configuration.GetConnectionString("DefaultConnection");
            var userStore = new UserStore(conn);
            var roleStore = new RoleStore(conn);

            services.AddSingleton <IUserStore <ApplicationUser> >(userStore);
            services.AddSingleton <IRoleStore <ApplicationRole> >(roleStore);

            // Add framework services.
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDbContext <MardisContext>(options =>
                                                  options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            var sessionTimeOut = Configuration.GetValue <int>("SessionTimeOut");

            services.AddIdentity <ApplicationUser, ApplicationRole>(config =>
            {
                config.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromMinutes(sessionTimeOut);
                config.Lockout = new LockoutOptions()
                {
                    DefaultLockoutTimeSpan = TimeSpan.FromHours(2)
                };
            })
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings
                options.Password.RequireDigit           = true;
                options.Password.RequiredLength         = 8;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = true;
                options.Password.RequireLowercase       = false;



                // Cookie settings
                options.Cookies.ApplicationCookie.LoginPath  = "/Account/Login";
                options.Cookies.ApplicationCookie.LogoutPath = "/Account/Login";

                // User settings
                options.User.RequireUniqueEmail = true;
            });

            services.Configure <FormOptions>(x => x.ValueCountLimit = 8192);

            services.AddDataProtection()
            .SetApplicationName("M@rdisEngin3")
            .SetDefaultKeyLifetime(TimeSpan.FromDays(14));


            // Add framework services.
            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver      = new DefaultContractResolver();
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            }
                            );

            services.AddDistributedMemoryCache();

            services.AddMemoryCache();
            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
            });



            services.AddSingleton <RedisCache, RedisCache>();

            //Add context to controllers
            services.AddDbContext <MardisContext>(opc => opc.UseSqlServer(conn));

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // Add application services.
            services.AddTransient <IEmailSender, AuthMessageSender>();
            services.AddTransient <ISmsSender, AuthMessageSender>();

            services.AddScoped <IMenuService, MenuService>();
        }