Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            IMvcBuilder builder = services.AddRazorPages();

#if DEBUG
            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif

            //Web Services
            services.AddTransient <IHttpContextAccessor, HttpContextAccessor>();

            //Required Servies
            services.AddApplication();
            services.AddInfrastructure();
            services.AddPersistence(Configuration);

            services.AddServerSideBlazor();

            services.AddTransient <SaveIpAddressFilter>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //login
            services.AddHttpClient();


            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath        = "/Login/Index";
                options.AccessDeniedPath = "/User/Forbidden/";
            });


            services.AddControllersWithViews().AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <LoginRequestValidator>());
            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
            });
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddTransient <IUserApiClient, UserApiClient>();
            //login
            IMvcBuilder builder     = services.AddRazorPages();
            var         environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

#if DEBUG
            if (environment == Environments.Development)
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpClient();
            services.AddControllersWithViews();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IProductApiClient, ProductApiClient>();
            services.AddTransient <ICategoryApiClient, CategoryApiClient>();
            services.AddTransient <IOrderApiClient, OrderApiClient>();


            services.AddControllers()
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <CreateOrderRequestValidator>());

            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromMinutes(60);
            });

            IMvcBuilder builder     = services.AddRazorPages();
            var         environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

#if DEBUG
            if (environment == Environments.Development)
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif
        }
Пример #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IMvcBuilder builder = services.AddRazorPages();

            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));

            services.AddScoped <ILeaveTypeRepository, LeaveTypeRepository>();
            services.AddScoped <ILeaveHistoryRepository, LeaveHistoryRepository>();
            services.AddScoped <ILeaveAllocationRepository, LeaveAllocationRepository>();

            services.AddAutoMapper(typeof(Mapper));

            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddRoles <IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddControllersWithViews();
            services.AddRazorPages();
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <PostContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Postinger")));
            services.AddRazorPages()
            .AddRazorRuntimeCompilation();
            services.AddControllersWithViews();
            IMvcBuilder builder = services.AddRazorPages();

            builder.AddRazorRuntimeCompilation();

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Jwt:Key"])),
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                };
            });
        }
Пример #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDbContext <CatalogContext>(options =>
                                                   options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDbContext <SalesContext>(options =>
                                                 options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDbContext <FinanceContext>(options =>
                                                   options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddControllersWithViews();

            IMvcBuilder builder = services.AddRazorPages();

#if DEBUG
            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif

            services.AddAutoMapper(typeof(DomainToDtoMappingProfile), typeof(DtoToDomainMappingProfile));

            services.AddMediatR(typeof(Startup));

            services.RegisterServices();
        }
Пример #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IUserApiClient, UserApiClient>();
            services.AddTransient <IRoleApiClient, RoleApiClient>();
            services.AddTransient <IProductApiClient, ProductApiClient>();
            services.AddTransient <ICategoryApiClient, CategoryApiClient>();
            services.AddTransient <IProductService, ProductService>();
            services.AddTransient <ICategoryService, CategoryService>();
            services.AddDbContext <MockProjectDbContext>(Options => Options.UseSqlServer(Configuration.GetConnectionString("MockProjectSolution")));
            services.AddHttpClient();
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
            {
                options.LoginPath        = "/Login/Index/";
                options.AccessDeniedPath = "/Login/Index";
            });
            services.AddControllersWithViews().
            AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <LoginRequestValidator>());
            IMvcBuilder builder = services.AddRazorPages();

            services.AddSession(options => {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
            });

            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

#if DEBUG
            if (environment == Environments.Development)
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif
        }
Пример #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IMvcBuilder builder = services.AddRazorPages();

            // Use SqLite for development and SQLServer for production
            if (Environment.IsDevelopment())
            {
                // Configure LiveReload
                // https://github.com/RickStrahl/Westwind.AspnetCore.LiveReload
                services.AddLiveReload();


                // for runtime compilation, ie, watching file changes
                // Note that you will still need to reload the page in the browser
                builder.AddRazorRuntimeCompilation();

                services.AddDbContext <RazorPagesMovieContext>(options =>
                                                               options.UseSqlite(Configuration.GetConnectionString("RazorPagesMovieContext")));
            }
            else
            {
                services.AddDbContext <RazorPagesMovieContext>(options =>
                                                               options.UseSqlServer(
                                                                   Configuration.GetConnectionString("MovieContext")));
            }
        }
Пример #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSession();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUnitRepository, UnitRepository>();
            services.AddScoped <IRecipeRepository, RecipeRepository>();
            services.AddScoped <IItemRepository, ItemRepository>();
            services.AddScoped <IItemCategoryRepository, ItemCategoryRepository>();
            services.AddScoped <IRecipeImageRepository, RecipeImageRepository>();
            services.AddScoped <IUserFavoriteRecipeRepository, UserFavoriteRecipeRepository>();

            services.AddDbContext <MyDbContext>();

            IMvcBuilder mvc = services.AddControllersWithViews();

#if (DEBUG)
            mvc.AddRazorRuntimeCompilation();
#endif

            services.AddRazorPages();
            services.AddMemoryCache();
            services.AddMvc().AddRazorPagesOptions(opt =>
            {
                opt.Conventions.AddPageRoute("/Home/Index", "");
            });

            //services.AddRouting(opt =>
            //{
            //	opt.ConstraintMap["recipeCountViewModel"] = typeof(string);
            //	opt.LowercaseUrls = true;
            //});
            services.AddControllersWithViews();
            services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
        }
Пример #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBehlogServices(Configuration);
            services.AddMvc(_ => {
                _.UseYeKeModelBinder();
            });
            services.AddDistributedMemoryCache();
            services.AddSession(options => {
                options.IdleTimeout        = TimeSpan.FromMinutes(30);
                options.Cookie.IsEssential = true;
            });
            services.AddDNTCommonWeb();
            IMvcBuilder mvc = services.AddControllersWithViews();

            mvc = services.AddRazorPages();

            mvc.AddApplicationPart(typeof(
                                       Admin.Controllers.PostController)
                                   .Assembly);
            mvc.AddApplicationPart(typeof(
                                       Identity.Controllers.LoginController)
                                   .Assembly);

            services.Configure <RouteOptions>(_ => {
                _.ConstraintMap.Add("reserved", typeof(BehlogReservedRouteConstraint));
            });
#if DEBUG
            if (Env.IsDevelopment())
            {
                mvc.AddRazorRuntimeCompilation();
            }
#endif
        }
Пример #11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IMvcBuilder builder = services.AddRazorPages();

            if (WebHostEnvironment.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
                services.AddDataProtection();
                services.AddControllersWithViews();
            }

            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.IdleTimeout        = TimeSpan.FromSeconds(600);
                options.Cookie.HttpOnly    = true;
                options.Cookie.IsEssential = true;
            });

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddScoped <IUsuarioServico, UsuarioServico>();
            services.AddScoped <ITarefaServico, TarefaServico>();

            services.AddScoped <IUsuarioRepositorio, UsuarioRepositorio>();
            services.AddScoped <ITarefaRepositorio, TarefaRepositorio>();

            services.AddDbContext <ProdapColaboradorDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ConnectionSql")));
            services.AddControllersWithViews();
        }
Пример #12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions <AppOptions>().Configure(options => options.Configure(Configuration));
            services.AddHostedService <DatabaseMigrationHostedService>();

            services.AddAppServices();
            services.AddAppAuthentication();
            services.AddAppAuthorization();

            services.AddDbContextFactory <ApplicationDbContext>(ConfigureDbContextOptions);
            services.AddDbContext <ApplicationDbContext>(ConfigureDbContextOptions);

            services.AddControllersWithViews()
            .AddNewtonsoftJson();
            services.AddProblemDetails(options =>
            {
                options.Map <GreenFieldAPIException>(ex => new GreenFieldAPIProblemDetails(ex));
                options.MapToStatusCode <GreenFieldValidationException>(StatusCodes.Status422UnprocessableEntity);
            });

            IMvcBuilder builder = services.AddRazorPages(options =>
            {
                options.Conventions.AllowAnonymousToPage("/Settings/New");
            });

            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }

            services.AddSignalR();
        }
Пример #13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry();

            /*
             * services.Configure<CookiePolicyOptions>(options =>
             * {
             *  // This lambda determines whether user consent for non-essential cookies is needed for a given request.
             *  options.CheckConsentNeeded = context => true;
             *  options.MinimumSameSitePolicy = SameSiteMode.None;
             * });
             */

            services.AddMvc().AddViewLocalization();
            services.AddLocalization(options => options.ResourcesPath = "Resources");

            if (Environment.EnvironmentName == "Development")
            {
                SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryMSI, new AzureIdentitySqlAuthenticationProvider());
                SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryManagedIdentity, new AzureIdentitySqlAuthenticationProvider());
            }

            services.AddDbContextPool <AlpinehutsDbContext>(options =>
            {
                options.UseSqlServer(Configuration["DatabaseConnectionString"]);
            });

            IMvcBuilder builder = services.AddRazorPages();

            if (Environment.EnvironmentName == "Development")
            {
                builder.AddRazorRuntimeCompilation();
            }
        }
Пример #14
0
    public IMvcBuilder ConfigureAspNetLibMvc(IMvcBuilder mvc)
    {
        // MVC の設定
        mvc = mvc.AddViewOptions(opt => opt.HtmlHelperOptions.ClientValidationEnabled = false);

        if (GlobalDaemonStateManager.EnableAspNetEnableRazorRuntimeCompilation)
        {
            // Razor 再コンパイルを有効化
            mvc = mvc.AddRazorRuntimeCompilation(opt =>
            {
                //以下を追加すると重くなるので追加しないようにした。その代わり Cores.Web の View をいじる場合は再コンパイルが必要
                //if (AspNetLib.LibRootFullPath._IsFilled())
                //    opt.FileProviders.Add(new PhysicalFileProvider(AspNetLib.LibRootFullPath));
            });
        }

        // この AspNetLib アセンブリのすべてのコントローラをデフォルト読み込み対象から除外する
        mvc = mvc.ConfigureApplicationPartManager(apm =>
        {
            List <ApplicationPart> removesList = new List <ApplicationPart>();

            apm.ApplicationParts.OfType <AssemblyPart>().Where(x => x.Assembly.Equals(ThisAssembly))._DoForEach(x => removesList.Add(x));

            removesList.ForEach(x => apm.ApplicationParts.Remove(x));

            apm.FeatureProviders.Add(new AspNetLibControllersProvider(this));
        });

        return(mvc);
    }
Пример #15
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.AddSingleton <IFeedService, FeedService>();
            services.AddSingleton <ILandingService, LandingService>();

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder
                                  .WithOrigins("http://host.docker.internal:4200")
                                  .AllowAnyMethod()
                                  .AllowAnyHeader());
            });

            services.AddAuthentication(IISDefaults.AuthenticationScheme);

            services.AddMvc(option => option.EnableEndpointRouting = false);

            IMvcBuilder builder = services.AddRazorPages();

//#if DEBUG
//            if (Env.IsDevelopment())
//            {
            builder.AddRazorRuntimeCompilation();
//            }
//#endif
        }
Пример #16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddAuthentication().AddMicrosoftAccount(microsoftOptions =>
            {
                microsoftOptions.ClientId     = Configuration["Authentication:Microsoft:ClientId"];
                microsoftOptions.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
            });

            services.AddAutoMapper();

            services.AddControllersWithViews();
            IMvcBuilder builder = services.AddRazorPages();

#if DEBUG
            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif
        }
Пример #17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("MSSqlConnection")));
            IdentityRegister.Register(services);
            RegisterDI.Register(services);

            services.AddMvc()
            .AddNewtonsoftJson(options => {
                options.SerializerSettings.ContractResolver      = new DefaultContractResolver();
                options.SerializerSettings.Formatting            = Formatting.Indented;
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });
            services.AddMemoryCache();
            services.AddDistributedMemoryCache();
            services.AddSession(cfg => {                    // Đăng ký dịch vụ Session
                cfg.Cookie.Name = "Ribmax";                 // Đặt tên Session - tên này sử dụng ở Browser (Cookie)
                cfg.IdleTimeout = new TimeSpan(0, 30, 0);   // Thời gian tồn tại của Session
            });
            IMvcBuilder builder = services.AddRazorPages();

            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
            AddElmah.AddService(services, Configuration);
        }
Пример #18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <AppDbContext>(options =>
                                                 options
                                                 .UseNpgsql(Configuration.GetConnectionString("DefaultConnection"))
                                                 .UseSnakeCaseNamingConvention()
                                                 );
            services
            .AddDefaultIdentity <AppUser>(options => {
                options.SignIn.RequireConfirmedAccount  = false;
                options.Password.RequiredLength         = 4;
                options.Password.RequiredUniqueChars    = 0;
                options.Password.RequireNonAlphanumeric = false;
            })
            .AddEntityFrameworkStores <AppDbContext>();
            services.AddControllersWithViews();
            services.AddHttpContextAccessor();
            services.AddRazorPages();
            IMvcBuilder builder = services.AddRazorPages();

#if DEBUG
            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif
            services.AddRepositories();
            services.AddSignalR();
            services.AddMediatR(typeof(Startup));
        }
Пример #19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddHttpClient();
            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath        = "/Login/index/";
                options.AccessDeniedPath = "/Home/Forbidden/";
            });

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IUserAPIClient, UserAPIClient>();


            IMvcBuilder builder     = services.AddRazorPages();
            var         environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

#if DEBUG
            if (environment == Environments.Development)
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif
        }
Пример #20
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDbContext <HosDbContext>(options =>
                                                 options.UseSqlite(
                                                     Configuration.GetConnectionString("HosConnection")));
            services.AddDbContext <RecDbContext>(options =>
                                                 options.UseSqlite(
                                                     Configuration.GetConnectionString("RecConnection")));
            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <ApplicationDbContext>();
            IMvcBuilder builder = services.AddRazorPages().AddRazorPagesOptions(options =>
            {
                // options.Conventions.AuthorizePage("/Contact");
                options.Conventions.AuthorizeFolder("/");
                // options.Conventions.AllowAnonymousToPage("/Private/PublicPage");
                // options.Conventions.AllowAnonymousToFolder("/Private/PublicPages");
            });

#if DEBUG
            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings.
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequiredLength         = 5;
                options.Password.RequiredUniqueChars    = 0;

                // Lockout settings.
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(5);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings.
                options.User.AllowedUserNameCharacters =
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail = false;
            });

            services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan  = TimeSpan.FromDays(2);

                options.LoginPath         = "/Identity/Account/Login";
                options.AccessDeniedPath  = "/Identity/Account/AccessDenied";
                options.SlidingExpiration = true;
            });
        }
Пример #21
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            string dbConnetionString = _confRoot.GetConnectionString("DefaultConnection");

            Console.WriteLine(dbConnetionString);

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(dbConnetionString));

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>     //CookieAuthenticationOptions
            {
                options.LoginPath = new PathString("/Profile/Login");
            });

            IMvcBuilder mvcBuilder = services.AddMvc(mvcOptions => mvcOptions.EnableEndpointRouting = false);

            if (_env.IsDevelopment())
            {
                mvcBuilder.AddRazorRuntimeCompilation();
            }
        }
Пример #22
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite(Configuration.GetConnectionString("CacheContext")));

            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddRoles <IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            IMvcBuilder builder = services.AddRazorPages();

            builder.AddRazorPagesOptions(options =>
            {
                options.Conventions.AddPageRoute("/Firearms/Index", "");
            });
#if DEBUG
            if (Environment.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif

            services.AddControllers(config =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                config.Filters.Add(new AuthorizeFilter(policy));
            });
        }
Пример #23
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();

            services.Configure <ForwardedHeadersOptions>(options => {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor
                                           | ForwardedHeaders.XForwardedProto;
            });

            services.AddMvcCore();

            IMvcBuilder mvcBuilder = services.AddControllersWithViews(
                options => {
                options.EnableEndpointRouting = false;

                options.Filters.Add(
                    new AutoValidateAntiforgeryTokenAttribute()
                    );
            }
                );

            if (_env.IsDevelopment())
            {
                mvcBuilder.AddRazorRuntimeCompilation();
            }
        }
Пример #24
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <ApplicationDbContext>();
            services.AddControllersWithViews();
            services.AddRazorPages();

            // Configure issue [Authorize] redirect to default login url
            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath        = "/Login";
                options.AccessDeniedPath = "/AccessDenied";
            });



#if  DEBUG
            //  Add html runtime refresh
            services.AddRazorPages().AddRazorRuntimeCompilation();

            IMvcBuilder builder = services.AddRazorPages();

            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif
        }
Пример #25
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDistributedMemoryCache();

            services.AddSession(options =>
            {
                options.IdleTimeout        = TimeSpan.FromHours(1);
                options.Cookie.HttpOnly    = true;
                options.Cookie.IsEssential = true;
            });

            services.AddControllers();

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));


            services.AddScoped <IDataSetRetriever, GitHubDataSetRetriever>();
            services.AddScoped <CovidDataUpdater>();
            services.AddHostedService <TimedDataUpdater>();

            IMvcBuilder builder = services.AddRazorPages();

#if DEBUG
            builder.AddRazorRuntimeCompilation();
#endif

            services.AddHttpContextAccessor();
        }
Пример #26
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IMvcBuilder builder = services.AddControllersWithViews();

#if DEBUG
            builder.AddRazorRuntimeCompilation();
#endif
        }
Пример #27
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Since ASP.NET Core 3.0, Razor file runtime compilation (so you can change a .cshtml file then
            // refresh in browser without restarting the server) must be enabled explicitly. See
            // https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.1
            IMvcBuilder builder = services.AddRazorPages();

#if DEBUG
            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
            services.AddAuthorization(options =>
            {
                options.AddPolicy("IsAuthenticated", policyBuilder => policyBuilder.RequireAuthenticatedUser());
                options.AddPolicy("IsAdmin", policyBuilder => policyBuilder.RequireClaim(FairClaims.IsAdmin.ToString(), true.ToString()));
                options.AddPolicy("IsSysAdmin", policyBuilder => policyBuilder.RequireClaim(FairClaims.IsSysAdmin.ToString(), true.ToString()));
                options.AddPolicy("CanReadSearch", policyBuilder => policyBuilder.AddRequirements(new CanReadSearchRequirement()));
                options.AddPolicy("CanWriteSearch", policyBuilder => policyBuilder.AddRequirements(new CanWriteSearchRequirement()));
            });
            services.AddSingleton <IAuthorizationHandler, CanReadSearchHandler>();
            services.AddSingleton <IAuthorizationHandler, CanWriteSearchHandler>();

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddControllersWithViews(options =>
            {
                options.Filters.Add(new AuthorizeFilter("IsAuthenticated"));
            });


            if (Configuration.GetValue <bool>("ActiveDirectory:UseMockAD"))
            {
                services.AddSingleton <IADService, MockADService>();
            }
            else
            {
                services.AddSingleton <IADService, ADService>();
            }

            services.AddDbContext <AppDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
            services.AddScoped <AuthenticationService>();
            services.AddScoped <UserService>();
            services.AddScoped <FileService>();
            services.AddScoped <DocumentService>();
            services.AddScoped <DepartmentService>();
            services.AddScoped <SearchService>();
            services.AddScoped <ApplicationTemplateService>();
            services.AddScoped <ApplicationService>();
            services.AddScoped <EvaluationService>();
        }
Пример #28
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpClient();
            // add multiple language
            var cultures = new[]
            {
                new CultureInfo("vi"),
                new CultureInfo("en")
            };

            // end add language
            services.AddControllersWithViews().AddExpressLocalization <ExpressLocalizationResource, ViewLocalizationResource>(ops =>
            {
                // When using all the culture providers, the localization process will
                // check all available culture providers in order to detect the request culture.
                // If the request culture is found it will stop checking and do localization accordingly.
                // If the request culture is not found it will check the next provider by order.
                // If no culture is detected the default culture will be used.

                // Checking order for request culture:
                // 1) RouteSegmentCultureProvider
                //      e.g. http://localhost:1234/tr
                // 2) QueryStringCultureProvider
                //      e.g. http://localhost:1234/?culture=tr
                // 3) CookieCultureProvider
                //      Determines the culture information for a request via the value of a cookie.
                // 4) AcceptedLanguageHeaderRequestCultureProvider
                //      Determines the culture information for a request via the value of the Accept-Language header.
                //      See the browsers language settings

                // Uncomment and set to true to use only route culture provider
                ops.UseAllCultureProviders     = false;
                ops.ResourcesPath              = "LocalizationResources";
                ops.RequestLocalizationOptions = o =>
                {
                    o.SupportedCultures     = cultures;
                    o.SupportedUICultures   = cultures;
                    o.DefaultRequestCulture = new RequestCulture("vi");
                };
            });;
            IMvcBuilder builder     = services.AddRazorPages();
            var         environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (environment == Environments.Development)
            {
                builder.AddRazorRuntimeCompilation();
            }
            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
            });
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <ISlideApiClient, SlideApiClient>();
            services.AddTransient <IProductApiClient, ProductApiClient>();
            services.AddTransient <ICategoryApiClient, CategoryApiClient>();
        }
Пример #29
0
        public void ConfigureServices(IServiceCollection services)
        {
            var rootConfiguration = CreateRootConfiguration();

            services.AddSingleton(rootConfiguration);

            IMvcBuilder builder = services.AddRazorPages();

            // update in Razor file compilation .net core 3.0   https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.0

            if (HostingEnvironment.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }



            // Add DbContexts for Asp.Net Core Identity, Logging and IdentityServer - Configuration store and Operational store
            RegisterDbContexts(services);

            // Add Asp.Net Core Identity Configuration and OpenIdConnect auth as well
            RegisterAuthentication(services);

            // Add exception filters in MVC
            services.AddMvcExceptionFilters();

            // Add all dependencies for IdentityServer Admin
            services.AddAdminServices <IdentityServerConfigurationDbContext, IdentityServerPersistedGrantDbContext, AdminLogDbContext>();

            // Add all dependencies for Asp.Net Core Identity
            // If you want to change primary keys or use another db model for Asp.Net Core Identity:
            services.AddAdminAspNetIdentityServices <AdminIdentityDbContext, IdentityServerPersistedGrantDbContext, UserDto <Guid>, Guid, RoleDto <Guid>, Guid, Guid, Guid,
                                                     XIdentityUser, XIdentityRole, Guid, XIdentityUserClaim, XIdentityUserRole,
                                                     XIdentityUserLogin, XIdentityRoleClaim, XIdentityUserToken,
                                                     UsersDto <UserDto <Guid>, Guid>, RolesDto <RoleDto <Guid>, Guid>, UserRolesDto <RoleDto <Guid>, Guid, Guid>,
                                                     UserClaimsDto <Guid>, UserProviderDto <Guid>, UserProvidersDto <Guid>, UserChangePasswordDto <Guid>,
                                                     RoleClaimsDto <Guid>, UserClaimDto <Guid>, RoleClaimDto <Guid> >();

            // Add all dependencies for Asp.Net Core Identity in MVC - these dependencies are injected into generic Controllers
            // Including settings for MVC and Localization
            // If you want to change primary keys or use another db model for Asp.Net Core Identity:
            services.AddMvcWithLocalization <UserDto <Guid>, Guid, RoleDto <Guid>, Guid, Guid, Guid,
                                             XIdentityUser, XIdentityRole, Guid, XIdentityUserClaim, XIdentityUserRole,
                                             XIdentityUserLogin, XIdentityRoleClaim, XIdentityUserToken,
                                             UsersDto <UserDto <Guid>, Guid>, RolesDto <RoleDto <Guid>, Guid>, UserRolesDto <RoleDto <Guid>, Guid, Guid>,
                                             UserClaimsDto <Guid>, UserProviderDto <Guid>, UserProvidersDto <Guid>, UserChangePasswordDto <Guid>,
                                             RoleClaimsDto <Guid> >(Configuration);

            // Add authorization policies for MVC
            RegisterAuthorization(services);

            // Add audit logging
            services.AddAuditEventLogging <AdminAuditLogDbContext, AuditLog>(Configuration);

            services.AddIdSHealthChecks <IdentityServerConfigurationDbContext, IdentityServerPersistedGrantDbContext, AdminIdentityDbContext, AdminLogDbContext, AdminAuditLogDbContext>(Configuration, rootConfiguration.AdminConfiguration);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplication();
            services.AddInfrastructure(Configuration);

            services.AddDatabaseDeveloperPageExceptionFilter();

            services.AddSingleton <ICurrentUserService, CurrentUserService>();

            services.AddHttpContextAccessor();

            services.AddHealthChecks()
            .AddDbContextCheck <ApplicationDbContext>();

            services.AddControllersWithViews(options =>
                                             options.Filters.Add <ApiExceptionFilterAttribute>())
            .AddFluentValidation();

            services.AddRazorPages();

            IMvcBuilder builder = services.AddRazorPages();

#if DEBUG
            if (Env.IsDevelopment())
            {
                builder.AddRazorRuntimeCompilation();
            }
#endif

            // Customise default API behaviour
            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            services.AddOpenApiDocument(configure =>
            {
                configure.Title = "CleanArchWeb API";
                configure.AddSecurity("JWT", Enumerable.Empty <string>(), new OpenApiSecurityScheme
                {
                    Type        = OpenApiSecuritySchemeType.ApiKey,
                    Name        = "Authorization",
                    In          = OpenApiSecurityApiKeyLocation.Header,
                    Description = "Type into the textbox: Bearer {your JWT token}."
                });

                configure.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
            });
        }