Exemplo n.º 1
0
        public static void RegisterComponents()
        {
            var container = new UnityContainer();

            DALModule.RegisterComponents(container);

            BLLModule.RegisterComponents(container);

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }
Exemplo n.º 2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            NinjectModule bllModule = new BLLModule();
            NinjectModule webModule = new WEBModule();
            var           kernel    = new StandardKernel(bllModule, webModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
Exemplo n.º 3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            NinjectModule webModule = new WEBModule();
            NinjectModule bllModule = new BLLModule("DefaultConnection");

            var kernel = new Ninject.StandardKernel(webModule, bllModule);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
Exemplo n.º 4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var serviceModule = new BLLModule(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
            var userModule    = new UserModule();
            var kernel        = new StandardKernel(userModule, serviceModule);

            kernel.Unbind <ModelValidatorProvider>();
            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version = "v1",
                    Title   = "User Management System API",
                });

                c.AddSecurityDefinition("Bearer",
                                        new OpenApiSecurityScheme
                {
                    In          = ParameterLocation.Header,
                    Description = "Please enter into field the word 'Bearer' following by space and JWT",
                    Name        = "Authorization",
                    Type        = SecuritySchemeType.ApiKey
                });

                var openApiSecurityScheme = new OpenApiSecurityScheme
                {
                    Reference = new OpenApiReference
                    {
                        Id   = "Bearer",
                        Type = ReferenceType.SecurityScheme,
                    },
                };

                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    { openApiSecurityScheme, new List <string>() },
                });
            });


            services.AddCors(options => options.AddPolicy(UserManagementPolicy, builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader()
                .WithExposedHeaders("Token-Expired");
            }));

            var authorizationConfigs = new AuthorizationConfigs();

            Configuration.Bind("Authorization", authorizationConfigs);
            services.AddSingleton(authorizationConfigs);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = TokenValidator.GetTokenValidationParameters(authorizationConfigs.TokenKey);
                x.Events = new JwtBearerEvents
                {
                    OnAuthenticationFailed = context =>
                    {
                        if (context.Exception.GetType() == typeof(SecurityTokenExpiredException))
                        {
                            context.Response.Headers.Add("Token-Expired", bool.TrueString);
                        }

                        return(Task.CompletedTask);
                    }
                };
            });

            BLLModule.Load(services, Configuration);
        }