// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { var gitBranchName = DatabaseStartupHelpers.GetWwwRootPath().GetBranchName(); // Add framework services. services.AddMvc(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //This makes the Git branch name available via injection services.AddSingleton(new AppInformation(gitBranchName)); var connection = Configuration.GetConnectionString("OverrideConnection"); if (connection == null) { connection = Configuration.GetConnectionString("DefaultConnection"); if (Configuration["ENVIRONMENT"] == "Development") { //if running in development mode then we alter the connection to have the branch name in it connection = connection.FormDatabaseConnection(gitBranchName); } } services.AddDbContext <EfCoreContext>(options => options.UseSqlServer(connection, b => b.MigrationsAssembly("DataLayer"))); //Add AutoFac var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule <ServiceLayer.Utils.MyAutoFacModule>(); containerBuilder.Populate(services); var container = containerBuilder.Build(); return(new AutofacServiceProvider(container)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var gitBranchName = DatabaseStartupHelpers.GetWwwRootPath().GetBranchName(); // Add framework services. services.AddMvc(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //This makes the Git branch name available via injection services.AddSingleton(new AppInformation(gitBranchName)); var connection = Configuration.GetConnectionString("DefaultConnection"); if (Configuration["ENVIRONMENT"] == "Development") { //if running in development mode then we alter the connection to have the branch name in it connection = connection.FormDatabaseConnection(gitBranchName); } services.AddDbContext <EfCoreContext>(options => options.UseSqlServer(connection, b => b.MigrationsAssembly("DataLayer"))); }