コード例 #1
0
ファイル: Startup.cs プロジェクト: rodjenihm/ZrakStore
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var jwtConfigSection = Configuration.GetSection("JwtConfig");

            services.Configure <JwtConfig>(jwtConfigSection);

            var connectionString = new DapperConnectionString(Configuration.GetConnectionString("AuthDb"));

            services.AddSingleton(connectionString);

            services.AddScoped <IAsyncUserRepository, DapperUserRepository>();
            services.AddScoped <IUserService, UserService>();

            services.AddScoped <IAsyncRoleRepository, DapperRoleRepository>();
            services.AddScoped <IRoleService, RoleService>();

            services.AddScoped <IPasswordHasher, PasswordHasher>();


            var appSettings = jwtConfigSection.Get <JwtConfig>();
            var key         = Encoding.ASCII.GetBytes(appSettings.SecretKey);

            //services.AddAuthentication(configureOptions =>
            //{
            //    configureOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            //    configureOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            //})
            //.AddJwtBearer(configureOptions =>
            //{
            //    configureOptions.RequireHttpsMetadata = false;
            //    configureOptions.SaveToken = true;
            //    configureOptions.TokenValidationParameters = new TokenValidationParameters
            //    {
            //        ValidateIssuerSigningKey = true,
            //        ValidateIssuer = true,
            //        ValidateAudience = true,
            //        ValidateLifetime = true,
            //        ValidIssuer = appSettings.Issuer,
            //        ValidAudience = appSettings.Audience,
            //        IssuerSigningKey = new SymmetricSecurityKey(key),
            //    };
            //});

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(configureOptions =>
            {
                configureOptions.Cookie.Name      = "Cookie.Zrak";
                configureOptions.LoginPath        = "/User/Login";
                configureOptions.AccessDeniedPath = "/Home/AccessDenied";
            });

            services.AddCors();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
コード例 #2
0
 public DapperPostRepository(DapperConnectionString connectionString)
 {
     this.connectionString = connectionString;
 }
コード例 #3
0
 public DapperThreadRepository(DapperConnectionString connectionString)
 {
     this.connectionString = connectionString;
 }