public R Invoke <R>(Func <ArvenaDbContext, R> func) { using (var arvenaDbContext = new ArvenaDbContext(_customConfig)) { return(func(arvenaDbContext)); } }
public void Invoke(Action <ArvenaDbContext> action) { using (var arvenaDbContext = new ArvenaDbContext(_customConfig)) { action(arvenaDbContext); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers() .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); var customConfig = Configuration.GetSection(typeof(CustomConfig).Name).Get <CustomConfig>(); //if (customConfig.IsProduction) //{ // customConfig.ConnectionString = // string.Format(customConfig.ConnectionString, "yexrewgv", "yEddLBhAqpuYlHD5LOCIq3gXuHs6taI0", "tai.db.elephantsql.com", "yexrewgv"); //} services.AddDbContext <ArvenaDbContext>( //options => options.UseSqlServer(customConfig.ConnectionString) ); services.AddSingleton <ICustomConfig>(x => customConfig); DependencyInjection.RegisterModules(services); var t = new ArvenaDbContext(customConfig).Sklep.Take(5).ToList(); }