Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Database Configuration
            services.AddDbContext <BookStoreContext>(op => op.UseSqlServer(Configuration.GetConnectionString("BookStoreConString")));

            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;
            });

            //Identity Configuration
            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores <BookStoreContext>();

            //Repository Configuration
            services.AddTransient <IBookRepository, BookRepository>();
            services.AddTransient <ICategoryRepository, CategoryRepository>();
            services.AddTransient <IOrderRepository, OrderRepository>();

            //For Shoping Cart
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped(sp => ShopingCart.GetShopingCart(sp));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //Temporary Service for Shoping Cart
            services.AddMemoryCache();
            services.AddSession();
        }