Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public virtual void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddDbContext <ConfigureModelsDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("StringConnection")));
            services.AddScoped(typeof(IRepository <>), typeof(Repository <>));
            ConfigureTypesBusiness.RegisterAllTypesBusiness(services);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            var key = Encoding.ASCII.GetBytes(TokenService.Secret);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            services.AddSwaggerGen(s =>
                                   s.SwaggerDoc("v1", new OpenApiInfoInfo {
                Title = "", Version = "v1"
            }));
        }
        public override void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddDbContext <ConfigureModelsDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("StringConnection")));
            services.AddScoped(typeof(IRepository <>), typeof(Repository <>));
            ConfigureTypesBusiness.RegisterAllTypesBusiness(services);
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }