예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            //register services
            //make sure SqlServer is being used(UseSqlServer) and pass from the configuration the connection string.
            //Takes AppDbContext action parameter and uses 'Default Connection' from appsettings.json
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlServer(_configurationRoot.GetConnectionString("DefaultConnection")));

            //Specify that I'm using the identity Service with built in classes IdentityUser, IdentityRole
            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores <AppDbContext>();

            //removed the 'mock' from MockCategoryRepository and MockPieRepository to reference the database
            //add transient method results in a new instance CategoryRepository being returned eveytime its requested
            services.AddTransient <ICategoryRepository, CategoryRepository>();

            services.AddTransient <IEventRepository, EventRepository>();
            //allows you to work with the context
            //Add Sinleton-every time we ask for a instance you get back the same instance
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            //AddScoped allows you to create an object associated with a request.It's differenet between different requests
            //When you browse to the site you get an instance of the shooping cart and
            //When I browse to the site I get a different instance of the shooping cart
            services.AddScoped <MyEvent>(sp => MyEvent.GetEventList(sp));
            //adds Mvc
            services.AddMvc();
            //session specific
            //enable working with ApplicationSession state
            services.AddMemoryCache();
            services.AddSession();
        }