Example #1
0
        // 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)
        {
            services.AddDBContext(Configuration);
            services.AddAppUserAuthentication();
            JwtHelper.AddJwt(services, Configuration);

            services.AddBLs();

            services.AddAutoMapperProfiles();

            services.AddSingleton <IJwtFactory, JwtFactory>();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("RaceUser", policy => policy.RequireClaim(Constants.Strings.JwtClaimIdentifiers.Rol, Constants.Strings.JwtClaims.ApiAccess));
            });

            services.TryAddTransient <IHttpContextAccessor, HttpContextAccessor>();

            services.AddAutoMapper(typeof(Startup));
            services.AddMvc(mvcOptions => mvcOptions.EnableEndpointRouting = false)
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddJsonOptions(a =>
            {
                a.JsonSerializerOptions.Converters.Add(new TrimmingJsonConverter());
            });
        }