Ejemplo n.º 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();

            services.AddDistributedMemoryCache();

            RepositoryService.Register <BookLibraryRepository>(
                Configuration["ConnectionStrings:DefaultConnection"].ToString().Replace("%CONTENTROOTPATH%", _contentRootPath)
                );
            RepositoryService.SetSessionExpirationTimeInMinutes(20);

            services.AddSession(options =>
            {
                options.Cookie.Name        = Configuration.GetSection("sessionConfig")["SessionCookieName"].ToString();
                options.IdleTimeout        = TimeSpan.FromMinutes(RepositoryService.SESSIONEXPIRATIONTIMEINMINUTES);
                options.Cookie.HttpOnly    = true;
                options.Cookie.IsEssential = true;
            });

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

            services.Configure <SessionConfig>(Configuration.GetSection("sessionConfig"));
            services.AddDbContext <BookLibraryContext>(options =>
                                                       options.UseSqlServer(RepositoryService.ConnectionString <BookLibraryRepository>()));

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>     //CookieAuthenticationOptions
            {
                options.LoginPath      = new Microsoft.AspNetCore.Http.PathString("/Account/Login");
                options.ExpireTimeSpan = TimeSpan.FromMinutes(RepositoryService.SESSIONEXPIRATIONTIMEINMINUTES);
            });

            services.AddControllersWithViews().AddRazorRuntimeCompilation();
        }
 public PersonsContext()
     : base(RepositoryService.ConnectionString <PersonsRepository>())
 {
 }