private IFrameworkContext CreateContext(ProviderType providerType, IDataStoreScope scope) { var optionsBuilder = new DbContextOptionsBuilder <FrameworkContext>(); IFrameworkContext context = null; switch (providerType) { case ProviderType.Sqlite: var sqliteOptions = scope == null? optionsBuilder.UseSqlite(_connectionString).Options: optionsBuilder.UseSqlite(scope.AsDbConnection()).Options; context = new SqliteDbContext(sqliteOptions); break; case ProviderType.MySql: var mySqlOptions = scope == null? optionsBuilder.UseMySql(_connectionString).Options: optionsBuilder.UseMySql(scope.AsDbConnection()).Options; context = new MySqlDbContext(mySqlOptions); break; default: throw new NotImplementedException($"No provider exists for '{providerType}'."); } return(scope != null? context.UseTransaction(scope.AsTransaction()) : context); }
private TContextInterface CreateContext(ProviderType providerType, IDataStoreScope scope) { var optionsBuilder = new DbContextOptionsBuilder <SessionScopedContext>(); TContextInterface context; switch (providerType) { case ProviderType.Sqlite: var sqliteOptions = scope == null? optionsBuilder.UseSqlite(_connectionString).Options: optionsBuilder.UseSqlite(scope.AsDbConnection()).Options; context = _factoryMethod(sqliteOptions); break; case ProviderType.MySql: var mySqlOptions = scope == null? optionsBuilder.UseMySql(_connectionString).Options: optionsBuilder.UseMySql(scope.AsDbConnection()).Options; context = _factoryMethod(mySqlOptions); break; default: throw new NotImplementedException($"No provider exists for '{providerType}'."); } if (scope != null) { context.ScopeTo(scope); return(context); } return(default);