protected override void OnModelCreating(ModelBuilder builder)
        {
            DbConfig.Init(builder);
            DbConfig.Configure();

            base.OnModelCreating(builder);
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Bonus Card API", Version = "v1"
                });
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "BonusCards.Web.xml");
                c.IncludeXmlComments(xmlPath);
                c.AddSecurityDefinition("JwtKey", new ApiKeyScheme {
                    Name = "Authorization", In = "header"
                });
                c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> >
                {
                    { "JwtKey", new List <string>() }
                });
                c.CustomSchemaIds(x => x.FullName);
            });

            services.AddAuthentication(c =>
            {
                c.DefaultAuthenticateScheme = "JwtBearer";
                c.DefaultChallengeScheme    = "JwtBearer";
            }).AddJwtBearer("JwtBearer", options =>
            {
                var secret = Encoding.UTF8.GetBytes(Configuration["Authorization Key"]);
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(secret),
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                    ValidateLifetime         = false,
                };
            });

            DbConfig.Configure(services, Configuration["ConnectionString"]);

            services.AddTransient <IServiceLocator, ServiceLocator>();
            CqrsConfig.Configure(services);

            services.AddScoped <CqrsBus>();
        }