// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            // When we register a type as Transient, every time a new instance is created.
            // Transient creates new instance for every service/ controller as well as for every request and every user.


            //services.AddTransient<IRepository<Pizza>, PizzaRepository>();
            //services.AddTransient<IRepository<Order>, OrderRepository>();
            //services.AddTransient<IRepository<User>, UserRepository>();
            services.AddTransient <IPizzaService, PizzaService>();
            services.AddTransient <IOrderService, OrderService>();
            services.AddTransient <IUserService, UserService>();



            DInjector.RegisterRepositories(services, Configuration);

            services.AddControllersWithViews();
            services.AddDbContext <PizzaDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("PizzaAppDatabaseConnectionString")));
            // ^^^^^^^  CAN BE MOVED TO DIHelper/DInjector.cs class with a method RegisterRepositories. Commented for simplicity and clarity

            //services.AddTransient<IPizzaService, PizzaService>();
            //services.AddTransient<IOrderService, OrderService>();
            //services.AddTransient<IUserService, UserService>();
            //DInjector.RegisterRepositories(services, Configuration);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            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().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // You know what to do here for homework
            // services.AddTransient<IStaticDb, StaticDb>();

            services.AddTransient <IPizzaService, PizzaService>();
            services.AddTransient <IOrderService, OrderService>();
            services.AddTransient <IUserService, UserService>();



            DInjector.RegisterRepositories(services, Configuration);
        }