// method runs after Constructor is done in first run // parameter of type IServiceCollection is passed into this method // doesn't return anything public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.AddDbContext <Models.ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:BilliardStoreProducts:ConnectionString"])); services.AddDbContext <Models.AppIdentityDbContext>(options => options.UseSqlServer(Configuration["Data:BilliardStoreIdentity:ConnectionString"])); services.AddIdentity <Microsoft.AspNetCore.Identity.IdentityUser, Microsoft.AspNetCore.Identity.IdentityRole>() .AddEntityFrameworkStores <BilliardStore.Models.AppIdentityDbContext>() .AddDefaultTokenProviders(); services.AddTransient <Models.IProductRepository, Models.EFProductRepository>(); services.AddScoped <Models.Cart>(sp => Models.SessionCart.GetCart(sp)); services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>(); services.AddTransient <Models.IOrderRepository, Models.EFOrderRepository>(); services.AddTransient <SendGrid.ISendGridClient>((s) => { return(new SendGrid.SendGridClient(Configuration.GetValue <string>("SendGrid:Key"))); }); services.AddTransient <Braintree.IBraintreeGateway>((s) => { return(new Braintree.BraintreeGateway( Configuration.GetValue <string>("Braintree:Environment"), Configuration.GetValue <string>("Braintree:MerchantId"), Configuration.GetValue <string>("Braintree:PublicKey"), Configuration.GetValue <string>("Braintree:PrivateKey"))); }); services.AddTransient <SmartyStreets.IClient <SmartyStreets.USStreetApi.Lookup> >((s) => { return(new SmartyStreets.ClientBuilder( Configuration.GetValue <string>("SmartyStreets:AuthId"), Configuration.GetValue <string>("SmartyStreets:AuthToken") ).BuildUsStreetApiClient()); }); services.AddMvc(); services.AddMemoryCache(); services.AddSession(); } // makes EFProductRepository take the place of IProductRepository in the code
public static void AddLogixSession(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration) { double sessionIdleTimeout = System.Convert.ToDouble(configuration["ConnectAuthentication:SessionLifeTime"]); services.AddSession ( options => { options.IdleTimeout = System.TimeSpan.FromSeconds(sessionIdleTimeout); } ); }
public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { services.Configure <SessionOptions>(option => option.IdleTimeout = TimeSpan.FromMinutes(30)); services.AddCaching(); services.AddSession(); services.AddMvc(); services.Configure <MvcOptions>(Router.Instance.Route); services.Configure <MvcOptions>(options => { //options.Filters.Add(typeof(ActionFilter)); //options.Filters.Add(typeof(ResultFilter)); //options.Filters.Add(typeof(AuthorizationFilter)); options.Filters.Add(typeof(ExceptionFilter)); }); services.AddEntityFramework().AddSqlServer().AddDbContext <ApplicationDbContext>(); }