Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
Exemplo n.º 3
0
        public static DbConnection AsDbConnection(this IDataStoreScope scope)
        {
            var connection = (DatabaseConnectionWrapper)scope.Connection;

            return(connection.Connection);
        }
Exemplo n.º 4
0
        public static DbTransaction AsTransaction(this IDataStoreScope scope)
        {
            var transaction = (DatabaseTransactionWrapper)scope.Transaction;

            return(transaction.Transaction);
        }
Exemplo n.º 5
0
 public void ScopeTo(IDataStoreScope scope)
 {
     Database.UseTransaction(scope.AsTransaction());
 }