Esempio n. 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IPasswordHasher, PasswordHasher>();
            services.AddSingleton <UserRepository>();
            services.AddSingleton <DocumentRepository>();
            services.AddSingleton <CurrentUserProvider>();

            services.AddSingleton(serviceProvider =>
            {
                var env = serviceProvider.GetRequiredService <IHostingEnvironment>();
                var db  = new PasswordManagerDatabase(Path.Combine(env.ContentRootPath, "db", "PasswordManager.json"));
                db.Load();
                return(db);
            });

            services.Configure <JwtAuthentication>(Configuration.GetSection("JwtAuthentication"));
            services.AddSingleton <IPostConfigureOptions <JwtBearerOptions>, ConfigureJwtBearerOptions>();
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer();
        }
Esempio n. 2
0
 public AdminController(PasswordManagerDatabase passwordManagerDatabase)
 {
     _passwordManagerDatabase = passwordManagerDatabase ?? throw new System.ArgumentNullException(nameof(passwordManagerDatabase));
 }