|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using System; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Mongo2Go; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.Modularity; |
|
|
|
@ -14,15 +15,17 @@ namespace Volo.Abp.MongoDB |
|
|
|
)] |
|
|
|
public class AbpMongoDbTestModule : AbpModule |
|
|
|
{ |
|
|
|
private MongoDbRunner _mongoDbRunner; |
|
|
|
private static readonly MongoDbRunner MongoDbRunner = MongoDbRunner.Start(); |
|
|
|
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
{ |
|
|
|
_mongoDbRunner = MongoDbRunner.Start(); |
|
|
|
var connectionString = MongoDbRunner.ConnectionString.EnsureEndsWith('/') + |
|
|
|
"Db_" + |
|
|
|
Guid.NewGuid().ToString("N"); |
|
|
|
|
|
|
|
Configure<DbConnectionOptions>(options => |
|
|
|
{ |
|
|
|
options.ConnectionStrings.Default = _mongoDbRunner.ConnectionString; |
|
|
|
options.ConnectionStrings.Default = connectionString; |
|
|
|
}); |
|
|
|
|
|
|
|
context.Services.AddMongoDbContext<TestAppMongoDbContext>(options => |
|
|
|
@ -31,10 +34,5 @@ namespace Volo.Abp.MongoDB |
|
|
|
options.AddRepository<City, CityRepository>(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
|
|
|
{ |
|
|
|
_mongoDbRunner.Dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|