Browse Source
Merge pull request #6053 from abpframework/maliming/IMongoClient
Add IMongoClient to the IAbpMongoDbContext.
pull/6058/head
Halil İbrahim Kalkan
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
9 additions and
5 deletions
-
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpMongoDbContext.cs
-
framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IAbpMongoDbContext.cs
-
framework/src/Volo.Abp.MongoDB/Volo/Abp/Uow/MongoDB/UnitOfWorkMongoDbContextProvider.cs
|
|
|
@ -1,5 +1,4 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using MongoDB.Bson; |
|
|
|
using MongoDB.Driver; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
|
|
|
|
@ -9,6 +8,8 @@ namespace Volo.Abp.MongoDB |
|
|
|
{ |
|
|
|
public IMongoModelSource ModelSource { get; set; } |
|
|
|
|
|
|
|
public IMongoClient Client { get; private set; } |
|
|
|
|
|
|
|
public IMongoDatabase Database { get; private set; } |
|
|
|
|
|
|
|
public IClientSessionHandle SessionHandle { get; private set; } |
|
|
|
@ -18,9 +19,10 @@ namespace Volo.Abp.MongoDB |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public virtual void InitializeDatabase(IMongoDatabase database, IClientSessionHandle sessionHandle) |
|
|
|
public virtual void InitializeDatabase(IMongoDatabase database, IMongoClient client, IClientSessionHandle sessionHandle) |
|
|
|
{ |
|
|
|
Database = database; |
|
|
|
Client = client; |
|
|
|
SessionHandle = sessionHandle; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -4,6 +4,8 @@ namespace Volo.Abp.MongoDB |
|
|
|
{ |
|
|
|
public interface IAbpMongoDbContext |
|
|
|
{ |
|
|
|
IMongoClient Client { get; } |
|
|
|
|
|
|
|
IMongoDatabase Database { get; } |
|
|
|
|
|
|
|
IMongoCollection<T> Collection<T>(); |
|
|
|
|
|
|
|
@ -59,7 +59,7 @@ namespace Volo.Abp.Uow.MongoDB |
|
|
|
} |
|
|
|
|
|
|
|
var dbContext = unitOfWork.ServiceProvider.GetRequiredService<TMongoDbContext>(); |
|
|
|
dbContext.ToAbpMongoDbContext().InitializeDatabase(database, null); |
|
|
|
dbContext.ToAbpMongoDbContext().InitializeDatabase(database, client, null); |
|
|
|
|
|
|
|
return dbContext; |
|
|
|
} |
|
|
|
@ -90,11 +90,11 @@ namespace Volo.Abp.Uow.MongoDB |
|
|
|
new MongoDbTransactionApi(session) |
|
|
|
); |
|
|
|
|
|
|
|
dbContext.ToAbpMongoDbContext().InitializeDatabase(database, session); |
|
|
|
dbContext.ToAbpMongoDbContext().InitializeDatabase(database, client, session); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
dbContext.ToAbpMongoDbContext().InitializeDatabase(database, activeTransaction.SessionHandle); |
|
|
|
dbContext.ToAbpMongoDbContext().InitializeDatabase(database, client, activeTransaction.SessionHandle); |
|
|
|
} |
|
|
|
|
|
|
|
return dbContext; |
|
|
|
|