2014-05-11 86 views
0

根據代碼文檔MongoServer.GetDatabaseMongoServer.GetDatabase不返回同一個實例

獲取表示該服務器上的數據庫MongoDatabase實例。 只有一個實例爲數據庫 設置每個組合創建。

但是,下面的測試失敗(我得到一個不同的實例回來,儘管數據庫名稱相同):

void describe_get_database() 
{ 
    MongoServer server = null; 
    MongoDatabase db = null; 
    MongoDatabase db2 = null; 
    string dbName = null; 

    before =() => 
    { 
     var client = new MongoClient("mongodb://localhost"); 
     server = client.GetServer(); 

     dbName = "test"; 
     db = server.GetDatabase(dbName); 
    }; 

    act =() => db2 = server.GetDatabase(dbName); 

    context["when the database name is the same"] =() => 
    { 
     it["should return the same database instance"] = 
      () => db2.should_be_same(db); 
    }; 
} 

我有沒有誤解的文件?

回答

0

我和Ben的觀察和問題,在這個問題上達成一致。

我連挖入蒙戈C#驅動程序的源代碼在[https://searchcode.com/codesearch/view/26539464/],並沒有顯示出所創建只有一個實例的線索。

/// <summary> 
    /// Gets a MongoDatabase instance representing a database on this server. Only one instance 
    /// is created for each combination of database settings. 
    /// </summary> 
    /// <param name="databaseName">The name of the database.</param> 
    /// <param name="databaseSettings">The settings to use with this database.</param> 
    /// <returns>A new or existing instance of MongoDatabase.</returns> 
    public virtual MongoDatabase GetDatabase(string databaseName, MongoDatabaseSettings databaseSettings) 
    { 
     if (databaseName == null) 
     { 
      throw new ArgumentNullException("databaseName"); 
     } 
     if (databaseSettings == null) 
     { 
      throw new ArgumentNullException("databaseSettings"); 
     } 
     return new MongoDatabase(this, databaseName, databaseSettings); 
    } 
相關問題