public void ConfigureServices(IServiceCollection services) { services.AddDbContext <AppDbContext>(options => options.UseSqlServer(_configurationRoot.GetConnectionString("DefaultConnection"))); //add dbcontext for EF services.AddTransient <ICategoryRepository, CategoryRepository>(); // register for DI services.AddTransient <IPieRepository, PieRepository>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <ShoppingCartModel>(sp => ShoppingCartModel.GetCart(sp)); services.AddMvc(); services.AddMemoryCache(); services.AddSession(); }
// 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.UseSqlServer(_config.GetConnectionString("GroceryDbConnection"))); services.AddIdentity <UserModel, IdentityRole>() .AddEntityFrameworkStores <AppDbContext>(); services.AddScoped <IProductRepository, SQLProductRepository>(); services.AddScoped <ICMSIndexRepository, SQLCMSIndexRepository>(); services.AddScoped <ISupplierRepository, SQLSuppliersRepository>(); services.AddScoped <IOrderRepository, SQLOrderRepository>(); services.AddScoped <IOrderItemRepository, SQLOrderItemRepository>(); services.AddScoped <IUserOrderItemRepository, SQLUserOrderItemRepository>(); services.AddScoped <IUserOrderRepository, SQLUserOrderRepository>(); services.AddScoped <IShoppingCartItemRepository, SQLShoppingCartItemRepository>(); services.AddScoped <IIncomeRepository, SQLIncomeRepository>(); services.AddScoped <IStatisticsRepository, SQLStatisticsRepository>(); services.AddScoped <INotesRepository, SQLNoteRepository>(); services.AddScoped <IChatRepository, SQLChatRepository>(); services.AddScoped <IInboxRepository, SQLInboxRepository>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped(sp => ShoppingCartModel.GetCart(sp)); services.AddSession(); services.AddMemoryCache(); services.AddControllersWithViews(options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); }); }