Пример #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            BsonSerializer.RegisterSerializer(typeof(DateTime), new DateTimeSerializer(DateTimeKind.Local, BsonType.DateTime));

            services.AddMemoryCache();
            services.AddDistributedMemoryCache();
            services.AddSession();

            services.AddMvc(config =>
                            config.Filters.Add <AuthorizationFilter>()
                            ).SetCompatibilityVersion(CompatibilityVersion.Latest);

            StartupConfiguration.ConfigureServices(services, Configuration);

            #region Repository

            services.AddScoped <AccountingSubjectRepository>();
            services.AddScoped <AuthorizationRepository>();
            services.AddScoped <BookRepository>();
            services.AddScoped <DetailRepository>();

            #endregion

            #region Service

            services.AddScoped <AuthorizationService>();

            #endregion
        }
Пример #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            BsonSerializer.RegisterSerializer(typeof(DateTime), new DateTimeSerializer(DateTimeKind.Local, BsonType.DateTime));

            StartupConfiguration.ConfigureServices(services, Configuration);

            #region Repository

            services.AddScoped <AccountingSubjectRepository>();
            services.AddScoped <AuthorizationRepository>();
            services.AddScoped <BookRepository>();
            services.AddScoped <DetailRepository>();

            #endregion

            #region Service

            services.AddScoped <AuthorizationService>();

            #endregion

            services.AddControllersWithViews();

            services
            .AddMvc()
            .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver            = new CamelCasePropertyNamesContractResolver())
            .AddJsonOptions(options => options.JsonSerializerOptions.PropertyNameCaseInsensitive = true)
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            services.AddAuthorization(options =>
            {
                options.AddPolicy("permissionRequirement", policy => policy.Requirements.Add(new PermissionRequirement()));
            }).AddAuthorizationPolicyEvaluator();
            services.AddScoped <IAuthorizationHandler, PermissionRequirementHandler>();

            services.AddAuthentication(options => options.AddScheme("PermissionHandler", o => o.HandlerType = typeof(PermissionHandler)));

            services.AddHttpClient();
            services.AddHttpClient("Heartbeat", client =>
            {
                client.Timeout = TimeSpan.FromSeconds(3);
            });
        }