/// <summary> /// Создает фабрику по настройкам /// </summary> /// <param name="configuration">настройки</param> /// <param name="connectionStringName">имя пар-ра со строкой подключения</param> /// <returns>фабрика</returns> public static IRepositoryContextFactory Create(IConfiguration configuration, string connectionStringName = "AppSettings:ConnectionString") { var connectionString = configuration[connectionStringName]; var result = new RepositoryContextFactory(connectionString); return(result); }
public OrdersDbContext CreateDbContext(string[] args) { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false, true) .AddJsonFile($"appsettings.{environment}.json", true) .AddEnvironmentVariables(); var config = builder.Build(); var repositoryFactory = RepositoryContextFactory.Create(config); return(repositoryFactory.CreateDbContext()); }