// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddDbContext <AppDbContext>(options => options.UseSqlServer(_configurationRoot.GetConnectionString("DefaultConnection"), x => x.MigrationsAssembly("emb"))); services.AddDefaultIdentity <IdentityUser>() .AddRoles <IdentityRole>() .AddEntityFrameworkStores <AppDbContext>(); 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.AddTransient <IRepositorioCategoria, RepositorioCategoria>(); services.AddTransient <IRepositorioProducto, RepositorioProducto>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IRepositorioOrden, RepositorioOrden>(); services.AddScoped(sp => Carrito.GetCarrito(sp)); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddMemoryCache(); services.AddSession(); return(services.BuildServiceProvider()); }
// 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; }); //Servicio para conectar el ApplicacionDbContext con sqlserver services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( "Server=(localdb)\\mssqllocaldb;Database=tiendaonlineDB;Trusted_Connection=True;MultipleActiveResultSets=true")); //Servicio para usar nuestra clase de usuario y configurarlo services.AddIdentity <tiendaOnlineUser, IdentityRole>(config => { config.SignIn.RequireConfirmedEmail = false; }) .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders() .AddDefaultUI(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddRazorPagesOptions(options => { options.AllowAreas = true; options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage"); options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout"); }); services.ConfigureApplicationCookie(options => { options.LoginPath = $"/Identity/Account/Login"; options.LogoutPath = $"/Identity/Account/Logout"; options.AccessDeniedPath = $"/Identity/Account/AccessDenied"; }); //Servicios Agregados por nosotros //Servicios para mandar correos de confirmacion... services.AddTransient <IEmailSender, EmailSender>(); services.Configure <AuthMessageSenderOptions>(Configuration); services.AddTransient <IProducto, ImpProducto>(); services.AddTransient <IOrden, ImpOrden>(); services.AddScoped(sp => Carrito.GetCarrito(sp)); //Configuracion del usuario services.Configure <IdentityOptions>(options => { // Password settings. options.Password.RequireDigit = false; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequiredLength = 6; options.Password.RequiredUniqueChars = 1; // Lockout settings. options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5); options.Lockout.MaxFailedAccessAttempts = 5; options.Lockout.AllowedForNewUsers = true; // User settings. options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+"; options.User.RequireUniqueEmail = true; }); }