private static void InitializeBindings(IKernel kernel)
        {
            var mapperConfiguration = MapperModule.Configure();

            kernel.Bind <MapperConfiguration>().ToConstant(mapperConfiguration).InSingletonScope();
            kernel.Bind <IMapper>().ToMethod(ctx => new Mapper(mapperConfiguration, type => ctx.Kernel.Get(type)));

            BLDependencyResolver.Initialize(kernel);
        }
Exemple #2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var connection = _configuration.GetConnectionString("Connection");

            services.AddDbContext <DvorContext>(options => options.UseSqlServer(connection));

            var apiAuthSettings    = AuthOperator.AddApiAuthSettings(_configuration, services);
            var cookieAuthSettings = AuthOperator.AddCookieAuthSettings(_configuration, services);

            services
            .AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie(options =>
            {
                options.SlidingExpiration = true;
                options.LoginPath         = "/Account/Login";
                options.AccessDeniedPath  = "/Account/AccessDenied";
                options.ExpireTimeSpan    = TimeSpan.FromSeconds(cookieAuthSettings.ExpirationTimeInSeconds);
            })
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    RequireExpirationTime    = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(apiAuthSettings.Secret)),
                    ValidIssuer      = apiAuthSettings.Issuer,
                    ValidateIssuer   = true,
                    ValidateAudience = false
                };
            });

            services.AddAuthorization();

            MapperModule.Configure(services);

            services.AddLocalization(options => options.ResourcesPath = "App_LocalResources");

            services.AddMvc()
            .AddViewLocalization()
            .AddJsonOptions(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);

            services.Configure <RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]
                {
                    new CultureInfo("en"),
                    new CultureInfo("ru")
                };

                options.DefaultRequestCulture = new RequestCulture("en");
                options.SupportedCultures     = supportedCultures;
                options.SupportedUICultures   = supportedCultures;
            });

            var builder = new ContainerBuilder();

            builder.RegisterModule <DIModule>();
            builder.Populate(services);
            var container = builder.Build();

            return(new AutofacServiceProvider(container));
        }