|
|
|
@ -62,8 +62,8 @@ namespace Volo.Abp.Uow.MongoDB |
|
|
|
$"A {nameof(IMongoDatabase)} instance can only be created inside a unit of work!"); |
|
|
|
} |
|
|
|
|
|
|
|
var connectionString = ResolveConnectionString(); |
|
|
|
var targetDbContextType = _options.GetReplacedTypeOrSelf(typeof(TMongoDbContext)); |
|
|
|
var connectionString = ResolveConnectionString(targetDbContextType); |
|
|
|
var dbContextKey = $"{targetDbContextType.FullName}_{connectionString}"; |
|
|
|
|
|
|
|
var mongoUrl = new MongoUrl(connectionString); |
|
|
|
@ -90,8 +90,8 @@ namespace Volo.Abp.Uow.MongoDB |
|
|
|
$"A {nameof(IMongoDatabase)} instance can only be created inside a unit of work!"); |
|
|
|
} |
|
|
|
|
|
|
|
var connectionString = await ResolveConnectionStringAsync(); |
|
|
|
var targetDbContextType = _options.GetReplacedTypeOrSelf(typeof(TMongoDbContext)); |
|
|
|
var connectionString = await ResolveConnectionStringAsync(targetDbContextType); |
|
|
|
var dbContextKey = $"{targetDbContextType.FullName}_{connectionString}"; |
|
|
|
|
|
|
|
var mongoUrl = new MongoUrl(connectionString); |
|
|
|
@ -244,33 +244,33 @@ namespace Volo.Abp.Uow.MongoDB |
|
|
|
return dbContext; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<string> ResolveConnectionStringAsync() |
|
|
|
private async Task<string> ResolveConnectionStringAsync(Type dbContextType) |
|
|
|
{ |
|
|
|
// Multi-tenancy unaware contexts should always use the host connection string
|
|
|
|
if (typeof(TMongoDbContext).IsDefined(typeof(IgnoreMultiTenancyAttribute), false)) |
|
|
|
{ |
|
|
|
using (_currentTenant.Change(null)) |
|
|
|
{ |
|
|
|
return await _connectionStringResolver.ResolveAsync<TMongoDbContext>(); |
|
|
|
return await _connectionStringResolver.ResolveAsync(dbContextType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return await _connectionStringResolver.ResolveAsync<TMongoDbContext>(); |
|
|
|
return await _connectionStringResolver.ResolveAsync(dbContextType); |
|
|
|
} |
|
|
|
|
|
|
|
[Obsolete("Use ResolveConnectionStringAsync method.")] |
|
|
|
private string ResolveConnectionString() |
|
|
|
private string ResolveConnectionString(Type dbContextType) |
|
|
|
{ |
|
|
|
// Multi-tenancy unaware contexts should always use the host connection string
|
|
|
|
if (typeof(TMongoDbContext).IsDefined(typeof(IgnoreMultiTenancyAttribute), false)) |
|
|
|
{ |
|
|
|
using (_currentTenant.Change(null)) |
|
|
|
{ |
|
|
|
return _connectionStringResolver.Resolve<TMongoDbContext>(); |
|
|
|
return _connectionStringResolver.Resolve(dbContextType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return _connectionStringResolver.Resolve<TMongoDbContext>(); |
|
|
|
return _connectionStringResolver.Resolve(dbContextType); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual CancellationToken GetCancellationToken(CancellationToken preferredValue = default) |
|
|
|
|