示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddAutoMapper(typeof(Startup));
            services.AddMediatR(typeof(Startup));

            services.AddCors();

            services.AddTransient <ICloudStorageService, CloudStorageService>();
            services.AddScoped <ContentContext>();
            services.AddScoped <LibraryContext>();
            services.AddSingleton <IQueueService>(opt =>
            {
                var queueService = AzureStorageQueueService.Create(Configuration["Azure:Storage:Events:ConnectionString"]);
                queueService.CreateQueue(Configuration["Azure:Storage:Queue:LogEventMPY:Name"]).Wait();

                return(queueService);
            });

            services.AddScoped(typeof(IPipelineBehavior <,>), typeof(EventLogBehavior <,>));

            services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority = Configuration["MPY:IdentityServer:Authority"];
                options.ApiName   = "MPY.Content";
                if (Environment.IsDevelopment())
                {
                    options.RequireHttpsMetadata = false;
                }
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("student", policyAdmin => policyAdmin.RequireClaim("role", "student"));
                options.AddPolicy("instructor", policyAdmin => policyAdmin.RequireClaim("role", "instructor"));
                options.AddPolicy("admin", policyAdmin => policyAdmin.RequireClaim("role", "admin"));
                options.AddPolicy("superadmin", policyAdmin => policyAdmin.RequireClaim("role", "superadmin"));
            });

            services.Configure <FormOptions>(options =>
            {
                options.MultipartBodyLengthLimit = 6000000000;
            });

            services.AddAntiforgery(options =>
            {
                // Set Cookie properties using CookieBuilder properties†.
                options.FormFieldName = "AntiforgeryFieldname";
                options.HeaderName    = "X-CSRF-TOKEN-HEADERNAME";
                options.SuppressXFrameOptionsHeader = false;
            });

            services.AddControllers(config =>
            {
                config.Filters.Add <GenerateAntiforgeryTokenCookieAttribute>();
                config.Filters.Add <DisableFormValueModelBindingAttribute>();
            }).SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_3_0);
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddAutoMapper(typeof(Startup));
            services.AddMediatR(typeof(Startup));

            services.AddCors();

            services.AddScoped <ProfileContext>();
            services.AddScoped <TribeContext>();
            services.AddSingleton <IQueueService>(opt =>
            {
                var queueService = AzureStorageQueueService.Create(Configuration["Azure:Storage:Events:ConnectionString"]);
                queueService.CreateQueue(Configuration["Azure:Storage:Queue:LogEventMPY:Name"]).Wait();

                return(queueService);
            });

            services.AddScoped(typeof(IPipelineBehavior <,>), typeof(EventLogBehavior <,>));

            services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority = Configuration["MPY:IdentityServer:Authority"];
                options.ApiName   = "MPY.Profile";
                if (Environment.IsDevelopment())
                {
                    options.RequireHttpsMetadata = false;
                }
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("student", policyAdmin => policyAdmin.RequireClaim("role", "student"));
                options.AddPolicy("instructor", policyAdmin => policyAdmin.RequireClaim("role", "instructor"));
                options.AddPolicy("admin", policyAdmin => policyAdmin.RequireClaim("role", "admin"));
                options.AddPolicy("superadmin", policyAdmin => policyAdmin.RequireClaim("role", "superadmin"));
            });
        }
示例#3
0
 public AddRegistrationCompletedEventToQueueCommandHandler(IConfiguration configuration)
 {
     _queueService = AzureStorageQueueService.Create(configuration["Azure:Storage:Events:ConnectionString"]);
     _queueService.CreateQueue(configuration["Azure:Storage:Queue:RegistrationEvent:Name"]);
 }