예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseContext"/> class.
 /// </summary>
 /// <param name="connection">
 /// The IDbConnection to use.
 /// </param>
 /// <param name="repositoryAdapter">
 /// The name qualifier for the database.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="connection"/> or <paramref name="repositoryAdapter"/> is null.
 /// </exception>
 /// <remarks>
 /// The supplied IDbConnection will not be closed/disposed - that remains the responsibility of the caller.
 /// </remarks>
 public DatabaseContext(
     [NotNull] IDbConnection connection,
     [NotNull] IRepositoryAdapter repositoryAdapter)
 {
     this.Connection               = connection ?? throw new ArgumentNullException(nameof(connection));
     this.RepositoryAdapter        = repositoryAdapter ?? throw new ArgumentNullException(nameof(repositoryAdapter));
     this.isConnectionUserProvided = true;
     this.connectionString         = connection.ConnectionString;
     this.pocoFactory              = new RaisedPocoFactory(this.RepositoryAdapter.DefinitionProvider);
 }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseContext"/> class.
        /// Construct a Database using a supplied connection string and a DbProviderFactory.
        /// </summary>
        /// <param name="connectionString">
        /// The database connection string to use.
        /// </param>
        /// <param name="providerFactory">
        /// The DbProviderFactory to use for instantiating IDbConnections.
        /// </param>
        /// <param name="repositoryAdapter">
        /// The entity definition provider.
        /// </param>
        /// <exception cref="ArgumentException">
        /// <paramref name="connectionString"/> is null or whitespace.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="providerFactory"/> or <paramref name="repositoryAdapter"/> is null.
        /// </exception>
        public DatabaseContext(
            [NotNull] string connectionString,
            [NotNull] DbProviderFactory providerFactory,
            [NotNull] IRepositoryAdapter repositoryAdapter)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException(ErrorMessages.ValueCannotBeNullOrWhiteSpace, nameof(connectionString));
            }

            this.factory           = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory));
            this.RepositoryAdapter = repositoryAdapter ?? throw new ArgumentNullException(nameof(repositoryAdapter));
            this.connectionString  = connectionString;
            this.pocoFactory       = new RaisedPocoFactory(this.RepositoryAdapter.DefinitionProvider);
        }