mirror of https://github.com/abpframework/abp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
using System;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MongoDB.Driver;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.Identity.MongoDB;
|
|
using Volo.Abp.MongoDB;
|
|
using Volo.Abp.Uow;
|
|
|
|
namespace Volo.Abp.OpenIddict.MongoDB;
|
|
|
|
[DependsOn(
|
|
typeof(OpenIddictTestBaseModule),
|
|
typeof(AbpIdentityMongoDbModule),
|
|
typeof(AbpOpenIddictMongoDbModule)
|
|
)]
|
|
public class OpenIddictMongoDbTestModule : AbpModule
|
|
{
|
|
private static string _connectionString;
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
_connectionString = MongoDbFixture.GetRandomConnectionString();
|
|
Configure<AbpDbConnectionOptions>(options =>
|
|
{
|
|
options.ConnectionStrings.Default = _connectionString;
|
|
});
|
|
}
|
|
|
|
public override void OnPreApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
Migrate(context);
|
|
}
|
|
|
|
private static void Migrate(ApplicationInitializationContext context)
|
|
{
|
|
var dbContexts = context.ServiceProvider.GetServices<IAbpMongoDbContext>();
|
|
|
|
foreach (var dbContext in dbContexts)
|
|
{
|
|
var mongoUrl = new MongoUrl(_connectionString);
|
|
var databaseName = mongoUrl.DatabaseName;
|
|
var client = new MongoClient(mongoUrl);
|
|
|
|
if (databaseName.IsNullOrWhiteSpace())
|
|
{
|
|
databaseName = ConnectionStringNameAttribute.GetConnStringName(dbContext.GetType());
|
|
}
|
|
|
|
(dbContext as AbpMongoDbContext)?.InitializeCollections(client.GetDatabase(databaseName));
|
|
}
|
|
}
|
|
}
|