Example #1
0
        public void ConfigureContainer(ServiceRegistry services)
        {
            services.AddControllers();
            services.AddSingleton(Log.Logger);

            services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
            services.AddAWSService <IAmazonS3>();
            services.AddAWSService <IAmazonTextract>();

            services.IncludeRegistry <DocumentAnalyzerServiceRegistry>();
        }
        public static void Register(ServiceRegistry services, IConfiguration configuration)
        {
            services.Configure <ConfigModel>(configuration);
            services.AddHttpContextAccessor();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("RequireAdminRole", policy => policy.RequireRole("Admin"));
                options.AddPolicy("RequireStandardRole", policy => policy.RequireRole("Standard"));
                options.AddPolicy("RequireDealerRole", policy => policy.RequireRole("Dealer"));
                options.AddPolicy("RequireCustomerRole", policy => policy.RequireRole("Customer"));
                options.AddPolicy("RequireDashboardUser", policy => policy.RequireClaim(ClaimType.CurrentUserRole, "Admin", "Dealer", "Standard"));
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                var signingKey    = Convert.FromBase64String(configuration["Jwt:SigningSecret"]);
                var validIssuer   = configuration["Jwt:ValidIssuer"];
                var validAudience = configuration["Jwt:ValidAudience"];
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidIssuer              = validIssuer,
                    ValidateAudience         = true,
                    ValidAudience            = validAudience,
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(signingKey),
                    ClockSkew = TimeSpan.Zero,       //dotnet gives 5-10 more minuts if ClockSkew is not set
                };
            });

            services.AddDefaultAWSOptions(configuration.GetAWSOptions());
            services.AddAWSService <IAmazonSimpleEmailService>();

            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMapperProfiles());
            });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            services.AddSwaggerDocumentation();
        }