Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDataProtection()
            .SetApplicationName("WebApp")
            .PersistKeysToFileSystem(new System.IO.DirectoryInfo(System.Environment.CurrentDirectory));

            services.AddIdentity <ApplicationUser, ApplicationRole>(options =>
            {
                options.SignIn.RequireConfirmedAccount     = false;
                options.SignIn.RequireConfirmedEmail       = false;
                options.SignIn.RequireConfirmedPhoneNumber = false;
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequiredLength         = 3;
                options.Password.RequiredUniqueChars    = 0;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
            })
            .AddDefaultTokenProviders();

            var _ConfigurationManager = new ConfigurationManager(Configuration);

            services.AddSingleton <IConfigurationManager>(_ConfigurationManager);
            services.AddSingleton <IUserStore <ApplicationUser>, UserStore>();
            services.AddSingleton <IRoleStore <ApplicationRole>, RoleStore>();
            services.AddSingleton <IArticleStore, ArticleStore>();
            services.AddSingleton <IInitializeDatabase, InitializeDatabase>();

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

            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath        = "/Login";
                options.AccessDeniedPath = "/AccessDenied";
            });

            // create database
            IInitializeDatabase database = new InitializeDatabase(_ConfigurationManager);

            services.AddSingleton <IInitializeDatabase>(database);
#if (DEBUG)
            // This code create database and structure only in debug
            database.CreateUpdateDb();
#endif
            services.AddRazorPages();
        }