Esempio n. 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connection = Configuration["ConexaoMySql:MySqlConnectionString"];

            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseMySql(connection)
                                                 );

            services.AddIdentity <ApplicationUser, IdentityRole>(options => {
                options.Password.RequiredLength         = 6;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireDigit           = false;
            })
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders();

            services.AddTransient <IProdutoRepository, ProdutoRepository>();
            services.AddTransient <ICategoriaRepository, CategoriaRepository>();
            services.AddTransient <IScoredRepository, ScoredRepository>();
            services.AddTransient <IPedidoRepository, PedidoRepository>();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();//encapsula todas as informações especificas de http sobre uma solicitação http individual

            services.AddScoped(cp => Carrinho.GetCarrinho(cp));


            services.AddSession();
            services.AddMemoryCache();

            services.AddControllersWithViews();
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            // Add application services.
            services.AddTransient <IEmailSender, EmailSender>();

            services.AddTransient <ICategoriaRepositorio, CategoriaRepositorio>();
            services.AddTransient <IProdutoRepositorio, ProdutoRepositorio>();
            services.AddTransient <IVendaRepositorio, VendaRepositorio>();


            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped(sp => Carrinho.GetCarrinho(sp));


            services.AddMvc();
            services.AddMemoryCache();
            services.AddSession();
        }