/// <inheritdoc />
        public static IDisposable Use(DatabaseCreationContext context)
        {
            var previousValue = Current;

            _current.Value = context;
            return(new DisposeAction(() => _current.Value = previousValue));
        }
        private IDatabase CreateDatabase(IUnitOfWork unitOfWork)
        {
            var creationContext = new DatabaseCreationContext();

            using (DatabaseCreationContext.Use(creationContext))
            {
                var database = CreateDatabase();
                if (unitOfWork.Options.IsTransactional)
                {
                    var dbtransaction = unitOfWork.Options.IsolationLevel.HasValue
                    ? database.Connection.BeginTransaction(unitOfWork.Options.IsolationLevel.Value)
                    : database.Connection.BeginTransaction();

                    unitOfWork.AddTransactionApi(
                        new TransactionApi(
                            dbtransaction,
                            database
                            )
                        );
                }

                return(database);
            }
        }