// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var jwtSettings = JwtSettings.FromConfiguration(Configuration);

            services.AddSingleton(jwtSettings);

            services.AddAutoMapper(typeof(Startup).GetTypeInfo().Assembly);
            services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);
            services.AddControllers();

            ConfigureAuthentication(services);
            ConfigureAuditContext(services);
            ConfigureSwagger(services);

            services.AddMvc(opt =>
            {
                opt.Filters.Add(typeof(ValidatorActionFilter));
            }).AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssemblyContaining <Startup>(); });

            services.AddSingleton <IUriService>(provider =>
            {
                var accessor    = provider.GetRequiredService <IHttpContextAccessor>();
                var request     = accessor.HttpContext.Request;
                var absoluteUri = string.Concat(request.Scheme, "://", request.Host.ToUriComponent(), "/");
                return(new UriService(absoluteUri));
            });

            services.AddScoped <IRequestManager, RequestManager>();
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(LoggingBehavior <,>));
            services.AddTransient <IAuditContextFactory, AuditContextFactory>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var jwtSettings = JwtSettings.FromConfiguration(Configuration);

            services.AddSingleton(jwtSettings);
            services.AddSingleton <IUserService, UserService>();
            services.AddControllers();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("admin", policy => policy.RequireClaim("can_delete", "true"));
                options.AddPolicy("user", policy => policy.RequireClaim("can_view", "true"));
            });
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options => options.TokenValidationParameters = jwtSettings.TokenValidationParameters);
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var jwtSettings = JwtSettings.FromConfiguration(Configuration);

            services.AddSingleton(jwtSettings);
            //services.AddHttpContextAccessor();

            var assembly = AppDomain.CurrentDomain.Load("EA.Audit.Common");

            services.AddAutoMapper(assembly);
            services.AddMediatR(assembly);
            services.AddControllers();

            ConfigureAuthentication(services);
            ConfigureAuditContext(services);
            ConfigureSwagger(services);

            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });

            services.AddMvc(opt =>
            {
                opt.Filters.Add(typeof(ValidatorActionFilter));
            }).AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssembly(assembly); });

            services.AddSingleton <IUriService, UriService>();

            services.AddScoped <IRequestManager, RequestManager>();
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(LoggingBehaviour <,>));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ExceptionBehaviour <,>));
            services.AddTransient <IAuditContextFactory, AuditContextFactory>();

            ConfigureRedis(services);
        }