Resolved #694: Auto configure defaults for entities for mongodb.

pull/696/head
Halil ibrahim Kalkan 7 years ago
parent debd0c37fa
commit 71b573bf60

@ -103,34 +103,6 @@ public class IdentityMongoModelBuilderConfigurationOptions
}
```
* **Do** explicitly configure `BsonClassMap` for all entities. Create a static method for this purpose. Example:
````C#
public static class AbpIdentityBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<IdentityUser>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<IdentityRole>(map =>
{
map.AutoMap();
});
});
}
}
````
`BsonClassMap` works with static methods. So, it is only needed to configure entities once in an application. `OneTimeRunner` guarantees that it runs in a thread safe manner and only once in the application life. Such a mapping above ensures that unit test properly run. This code will be called by the **module class** below.
### Repository Implementation
- **Do** **inherit** the repository from the `MongoDbRepository<TMongoDbContext, TEntity, TKey>` class and implement the corresponding repository interface. Example:
@ -187,8 +159,6 @@ public class AbpIdentityMongoDbModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpIdentityBsonClassMap.Configure();
context.Services.AddMongoDbContext<AbpIdentityMongoDbContext>(options =>
{
options.AddRepository<IdentityUser, MongoIdentityUserRepository>();

@ -1,8 +1,8 @@
## Entity Framework Core Integration
# Entity Framework Core Integration
This document explains how to integrate EF Core as an ORM provider to ABP based applications and how to configure it.
### Installation
## Installation
`Volo.Abp.EntityFrameworkCore` is the main nuget package for the EF Core integration. Install it to your project (for a layered application, to your data/infrastructure layer):
@ -28,7 +28,7 @@ namespace MyCompany.MyProject
> Note: Instead, you can directly download a [startup template](https://abp.io/Templates) with EF Core pre-installed.
### Creating DbContext
## Creating DbContext
You can create your DbContext as you normally do. It should be derived from `AbpDbContext<T>` as shown below:
@ -50,7 +50,21 @@ namespace MyCompany.MyProject
}
````
### Registering DbContext To Dependency Injection
### Configure the Connection String Selection
If you have multiple databases in your application, you can configure the connection string name for your DbContext using the `[ConnectionStringName]` attribute. Example:
```csharp
[ConnectionStringName("MySecondConnString")]
public class MyDbContext : AbpDbContext<MyDbContext>
{
}
```
If you don't configure, the `Default` connection string is used. If you configure a specific connection string name, but not define this connection string name in the application configuration then it fallbacks to the `Default` connection string.
## Registering DbContext To Dependency Injection
Use `AddAbpDbContext` method in your module to register your DbContext class for [dependency injection](Dependency-Injection.md) system.
@ -74,7 +88,7 @@ namespace MyCompany.MyProject
}
````
#### Add Default Repositories
### Add Default Repositories
ABP can automatically create default [generic repositories](Repositories.md) for the entities in your DbContext. Just use `AddDefaultRepositories()` option on the registration:
@ -137,7 +151,7 @@ public class BookManager : DomainService
This sample uses `InsertAsync` method to insert a new entity to the database.
#### Add Custom Repositories
### Add Custom Repositories
Default generic repositories are powerful enough in most cases (since they implement `IQueryable`). However, you may need to create a custom repository to add your own repository methods.
@ -173,7 +187,7 @@ public class BookRepository : EfCoreRepository<BookStoreDbContext, Book, Guid>,
Now, it's possible to [inject](Dependency-Injection.md) the `IBookRepository` and use the `DeleteBooksByType` method when needed.
##### Override Default Generic Repository
#### Override Default Generic Repository
Even if you create a custom repository, you can still inject the default generic repository (`IRepository<Book, Guid>` for this example). Default repository implementation will not use the class you have created.
@ -199,7 +213,7 @@ public override async Task DeleteAsync(
}
````
#### Access to the EF Core API
### Access to the EF Core API
In most cases, you want to hide EF Core APIs behind a repository (this is the main purpose of the repository). However, if you want to access the DbContext instance over the repository, you can use `GetDbContext()` or `GetDbSet()` extension methods. Example:
@ -225,9 +239,9 @@ public class BookService
> Important: You must reference to the `Volo.Abp.EntityFrameworkCore` package from the project you want to access to the DbContext. This breaks encapsulation, but this is what you want in that case.
#### Advanced Topics
### Advanced Topics
##### Set Default Repository Classes
#### Set Default Repository Classes
Default generic repositories are implemented by `EfCoreRepository` class by default. You can create your own implementation and use it for default repository implementation.
@ -272,7 +286,7 @@ context.Services.AddAbpDbContext<BookStoreDbContext>(options =>
});
```
##### Set Base DbContext Class or Interface for Default Repositories
#### Set Base DbContext Class or Interface for Default Repositories
If your DbContext inherits from another DbContext or implements an interface, you can use that base class or interface as DbContext for default repositories. Example:
@ -304,7 +318,7 @@ public class BookRepository : EfCoreRepository<IBookStoreDbContext, Book, Guid>,
One advantage of using interface for a DbContext is then it becomes replaceable by another implementation.
##### Replace Other DbContextes
#### Replace Other DbContextes
Once you properly define and use an interface for DbContext, then any other implementation can replace it using the `ReplaceDbContext` option:

@ -1,8 +1,8 @@
## MongoDB Integration
# MongoDB Integration
This document explains how to integrate MongoDB as a database provider to ABP based applications and how to configure it.
### Installation
## Installation
`Volo.Abp.MongoDB` is the main nuget package for the MongoDB integration. Install it to your project (for a layered application, to your data/infrastructure layer):
@ -26,7 +26,7 @@ namespace MyCompany.MyProject
}
```
### Creating a Mongo Db Context
## Creating a Mongo Db Context
ABP introduces **Mongo Db Context** concept (which is similar to Entity Framework Core's DbContext) to make it easier to use collections and configure them. An example is shown below:
@ -39,19 +39,62 @@ public class MyDbContext : AbpMongoDbContext
protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
modelBuilder.Entity<Question>(b =>
{
b.CollectionName = "Questions";
});
base.CreateModel(modelBuilder);
//Customize the configuration for your collections.
}
}
```
* It's derived from `AbpMongoDbContext` class.
* Adds a public `IMongoCollection<TEntity>` property for each mongo collection. ABP uses these properties to create default repositories by default.
* Overriding `CreateModel` method allows to configure collections (like their collection name in the database).
* Overriding `CreateModel` method allows to configure collection configuration.
### Configure Mapping for a Collection
ABP automatically register entities to MongoDB client library for all `IMongoCollection<TEntity>` properties in your DbContext. For the example above, `Question` and `Category` entities are automatically registered.
For each registered entity, it calls `AutoMap()` and configures known properties of your entity. For instance, if your entity implements `IHasExtraProperties` interface (which is already implemented for every aggregate root by default), it automatically configures `ExtraProperties`.
So, most of times you don't need to explicitly configure registration for your entities. However, if you need it you can do it by overriding the `CreateModel` method in your DbContext. Example:
````csharp
protected override void CreateModel(IMongoModelBuilder modelBuilder)
{
base.CreateModel(modelBuilder);
modelBuilder.Entity<Question>(b =>
{
b.CollectionName = "MyQuestions"; //Sets the collection name
b.BsonMap.UnmapProperty(x => x.MyProperty); //Ignores 'MyProperty'
});
}
````
This example changes the mapped collection name to 'MyQuestions' in the database and ignores a property in the `Question` class.
If you only need to configure the collection name, you can also use `[MongoCollection]` attribute for the collection in your DbContext. Example:
````csharp
[MongoCollection("MyQuestions")] //Sets the collection name
public IMongoCollection<Question> Questions => Collection<Question>();
````
### Configure the Connection String Selection
If you have multiple databases in your application, you can configure the connection string name for your DbContext using the `[ConnectionStringName]` attribute. Example:
````csharp
[ConnectionStringName("MySecondConnString")]
public class MyDbContext : AbpMongoDbContext
{
}
````
If you don't configure, the `Default` connection string is used. If you configure a specific connection string name, but not define this connection string name in the application configuration then it fallbacks to the `Default` connection string.
### Registering DbContext To Dependency Injection
## Registering DbContext To Dependency Injection
Use `AddAbpDbContext` method in your module to register your DbContext class for [dependency injection](Dependency-Injection.md) system.
@ -75,7 +118,7 @@ namespace MyCompany.MyProject
}
```
#### Add Default Repositories
### Add Default Repositories
ABP can automatically create default [generic repositories](Repositories.md) for the entities in your DbContext. Just use `AddDefaultRepositories()` option on the registration:
@ -138,7 +181,7 @@ public class BookManager : DomainService
This sample uses `InsertAsync` method to insert a new entity to the database.
#### Add Custom Repositories
### Add Custom Repositories
Default generic repositories are powerful enough in most cases (since they implement `IQueryable`). However, you may need to create a custom repository to add your own repository methods.
@ -182,7 +225,7 @@ public class BookRepository :
Now, it's possible to [inject](Dependency-Injection.md) the `IBookRepository` and use the `DeleteBooksByType` method when needed.
##### Override Default Generic Repository
#### Override Default Generic Repository
Even if you create a custom repository, you can still inject the default generic repository (`IRepository<Book, Guid>` for this example). Default repository implementation will not use the class you have created.
@ -208,7 +251,7 @@ public override async Task DeleteAsync(
}
```
#### Access to the MongoDB API
### Access to the MongoDB API
In most cases, you want to hide MongoDB APIs behind a repository (this is the main purpose of the repository). However, if you want to access the MongoDB API over the repository, you can use `GetDatabase()` or `GetCollection()` extension methods. Example:
@ -232,9 +275,9 @@ public class BookService
> Important: You must reference to the `Volo.Abp.MongoDB` package from the project you want to access to the MongoDB API. This breaks encapsulation, but this is what you want in that case.
#### Advanced Topics
### Advanced Topics
##### Set Default Repository Classes
#### Set Default Repository Classes
Default generic repositories are implemented by `MongoDbRepository` class by default. You can create your own implementation and use it for default repository implementation.
@ -279,7 +322,7 @@ context.Services.AddMongoDbContext<BookStoreMongoDbContext>(options =>
});
```
##### Set Base MongoDbContext Class or Interface for Default Repositories
#### Set Base MongoDbContext Class or Interface for Default Repositories
If your MongoDbContext inherits from another MongoDbContext or implements an interface, you can use that base class or interface as the MongoDbContext for default repositories. Example:
@ -313,7 +356,7 @@ public class BookRepository
One advantage of using interface for a MongoDbContext is then it becomes replaceable by another implementation.
##### Replace Other DbContextes
#### Replace Other DbContextes
Once you properly define and use an interface for a MongoDbContext , then any other implementation can replace it using the `ReplaceDbContext` option:

@ -1,17 +1,42 @@
using MongoDB.Bson.Serialization;
using System;
using MongoDB.Bson.Serialization;
using Volo.Abp.Data;
namespace Volo.Abp.MongoDB
{
public static class AbpBsonClassMapExtensions
{
public static void ConfigureExtraProperties<T>(this BsonClassMap<T> map)
where T : class, IHasExtraProperties
public static void ConfigureAbpConventions(this BsonClassMap map)
{
map.AutoMap();
map.ConfigureExtraProperties();
}
public static void ConfigureExtraProperties<TEntity>(this BsonClassMap<TEntity> map)
where TEntity : class, IHasExtraProperties
{
map.SetExtraElementsMember(new BsonMemberMap(
map,
typeof(T).GetMember(nameof(IHasExtraProperties.ExtraProperties))[0])
typeof(TEntity).GetMember(nameof(IHasExtraProperties.ExtraProperties))[0])
);
}
/// <summary>
/// Configures SetExtraElementsMember if the <see cref="BsonClassMap.ClassType"/>
/// implements the <see cref="IHasExtraProperties"/> interface.
/// Otherwise, does nothing
/// </summary>
public static void ConfigureExtraProperties(this BsonClassMap map)
{
if (map.ClassType.IsAssignableTo<IHasExtraProperties>())
{
map.SetExtraElementsMember(
new BsonMemberMap(
map,
map.ClassType.GetMember(nameof(IHasExtraProperties.ExtraProperties))[0]
)
);
}
}
}
}

@ -1,60 +0,0 @@
using System;
using System.Collections.Generic;
using MongoDB.Bson.Serialization;
using Volo.Abp.Data;
namespace Volo.Abp.MongoDB
{
public static class AbpGlobalBsonClassMap
{
private static readonly HashSet<Type> PreConfiguredTypes = new HashSet<Type>();
/// <summary>
/// Configure default/base properties for the entity using <see cref="BsonClassMap"/>.
/// This method runs single time for an <typeparamref name="TEntity"/> for the application lifetime.
/// Subsequent calls has no effect for the same <typeparamref name="TEntity"/>.
/// </summary>
public static void ConfigureDefaults<TEntity>()
{
ConfigureDefaults(typeof(TEntity));
}
/// <summary>
/// Configure default/base properties for the entity using <see cref="BsonClassMap"/>.
/// This method runs single time for an <paramref name="entityType"/> for the application lifetime.
/// Subsequent calls has no effect for the same <paramref name="entityType"/>.
/// </summary>
public static void ConfigureDefaults(Type entityType)
{
lock (PreConfiguredTypes)
{
if (PreConfiguredTypes.Contains(entityType))
{
return;
}
ConfigureDefaultsInternal(entityType);
PreConfiguredTypes.Add(entityType);
}
}
private static void ConfigureDefaultsInternal(Type entityType)
{
var map = new BsonClassMap(entityType);
map.AutoMap();
if (entityType.IsAssignableTo<IHasExtraProperties>())
{
map.SetExtraElementsMember(
new BsonMemberMap(
map,
entityType.GetMember(nameof(IHasExtraProperties.ExtraProperties))[0]
)
);
}
BsonClassMap.RegisterClassMap(map);
}
}
}

@ -0,0 +1,9 @@
using MongoDB.Bson.Serialization;
namespace Volo.Abp.MongoDB
{
public interface IHasBsonClassMap
{
BsonClassMap GetMap();
}
}

@ -0,0 +1,23 @@
using System;
using MongoDB.Bson.Serialization;
namespace Volo.Abp.MongoDB
{
public interface IMongoEntityModelBuilder<TEntity>
{
Type EntityType { get; }
string CollectionName { get; set; }
BsonClassMap<TEntity> BsonMap { get; }
}
public interface IMongoEntityModelBuilder
{
Type EntityType { get; }
string CollectionName { get; set; }
BsonClassMap BsonMap { get; }
}
}

@ -6,10 +6,10 @@ namespace Volo.Abp.MongoDB
{
public interface IMongoModelBuilder
{
void Entity<TEntity>([NotNull] Action<MongoEntityModelBuilder> buildAction);
void Entity<TEntity>(Action<IMongoEntityModelBuilder<TEntity>> buildAction = null);
void Entity([NotNull] Type entityType, [NotNull] Action<MongoEntityModelBuilder> buildAction);
void Entity([NotNull] Type entityType, Action<IMongoEntityModelBuilder> buildAction = null);
IReadOnlyList<MongoEntityModelBuilder> GetEntities();
IReadOnlyList<IMongoEntityModel> GetEntities();
}
}

@ -1,18 +1,33 @@
using MongoDB.Bson.Serialization;
using System;
namespace Volo.Abp.MongoDB
{
public class MongoEntityModelBuilder : IMongoEntityModel
public class MongoEntityModelBuilder<TEntity> :
IMongoEntityModel,
IHasBsonClassMap,
IMongoEntityModelBuilder,
IMongoEntityModelBuilder<TEntity>
{
public Type EntityType { get; }
public string CollectionName { get; set; }
public MongoEntityModelBuilder(Type entityType)
BsonClassMap IMongoEntityModelBuilder.BsonMap => _bsonClassMap;
BsonClassMap<TEntity> IMongoEntityModelBuilder<TEntity>.BsonMap => _bsonClassMap;
private readonly BsonClassMap<TEntity> _bsonClassMap;
public MongoEntityModelBuilder()
{
Check.NotNull(entityType, nameof(entityType));
EntityType = typeof(TEntity);
_bsonClassMap = new BsonClassMap<TEntity>();
_bsonClassMap.ConfigureAbpConventions();
}
EntityType = entityType;
public BsonClassMap GetMap()
{
return _bsonClassMap;
}
}
}

@ -1,46 +1,71 @@
using MongoDB.Bson.Serialization;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using JetBrains.Annotations;
namespace Volo.Abp.MongoDB
{
public class MongoModelBuilder : IMongoModelBuilder
{
private readonly Dictionary<Type, MongoEntityModelBuilder> _entityModelBuilders;
private readonly Dictionary<Type, object> _entityModelBuilders;
private static readonly object SyncObj = new object();
public MongoModelBuilder()
{
_entityModelBuilders = new Dictionary<Type, MongoEntityModelBuilder>();
_entityModelBuilders = new Dictionary<Type, object>();
}
public MongoDbContextModel Build()
{
var entityModels = _entityModelBuilders
.Select(x => x.Value)
.ToImmutableDictionary(x => x.EntityType, x => (IMongoEntityModel) x);
.Cast<IMongoEntityModel>()
.ToImmutableDictionary(x => x.EntityType, x => x);
foreach (var entityModel in entityModels.Values)
{
var map = entityModel.As<IHasBsonClassMap>().GetMap();
lock (SyncObj)
{
if (!BsonClassMap.IsClassMapRegistered(map.ClassType))
{
BsonClassMap.RegisterClassMap(map);
}
}
}
return new MongoDbContextModel(entityModels);
}
public virtual void Entity<TEntity>([NotNull] Action<MongoEntityModelBuilder> buildAction)
public virtual void Entity<TEntity>(Action<IMongoEntityModelBuilder<TEntity>> buildAction = null)
{
Entity(typeof(TEntity), buildAction);
var model = (IMongoEntityModelBuilder<TEntity>)_entityModelBuilders.GetOrAdd(
typeof(TEntity),
() => new MongoEntityModelBuilder<TEntity>()
);
buildAction?.Invoke(model);
}
public virtual void Entity([NotNull] Type entityType, [NotNull] Action<MongoEntityModelBuilder> buildAction)
public virtual void Entity(Type entityType, Action<IMongoEntityModelBuilder> buildAction = null)
{
Check.NotNull(entityType, nameof(entityType));
Check.NotNull(buildAction, nameof(buildAction));
var model = _entityModelBuilders.GetOrAdd(entityType, () => new MongoEntityModelBuilder(entityType));
buildAction(model);
var model = (IMongoEntityModelBuilder)_entityModelBuilders.GetOrAdd(
entityType,
() => (IMongoEntityModelBuilder)Activator.CreateInstance(
typeof(MongoEntityModelBuilder<>).MakeGenericType(entityType)
)
);
buildAction?.Invoke(model);
}
public virtual IReadOnlyList<MongoEntityModelBuilder> GetEntities()
public virtual IReadOnlyList<IMongoEntityModel> GetEntities()
{
return _entityModelBuilders.Values.ToImmutableList();
return _entityModelBuilders.Values.Cast<IMongoEntityModel>().ToImmutableList();
}
}
}

@ -58,8 +58,6 @@ namespace Volo.Abp.MongoDB
{
b.CollectionName = collectionAttribute?.CollectionName ?? collectionProperty.Name;
});
AbpGlobalBsonClassMap.ConfigureDefaults(entityType);
}
protected virtual void BuildModelFromDbContextInstance(IMongoModelBuilder modelBuilder, AbpMongoDbContext dbContext)

@ -1,21 +0,0 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.Threading;
namespace Volo.Abp.AuditLogging.MongoDB
{
public static class AbpAuditLoggingBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<AuditLog>(map =>
{
map.AutoMap();
});
});
}
}
}

@ -10,8 +10,6 @@ namespace Volo.Abp.AuditLogging.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpAuditLoggingBsonClassMap.Configure();
context.Services.AddMongoDbContext<AuditLoggingMongoDbContext>(options =>
{
options.AddRepository<AuditLog, MongoAuditLogRepository>();

@ -1,23 +0,0 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.MongoDB;
using Volo.Abp.Threading;
namespace Volo.Abp.BackgroundJobs.MongoDB
{
public static class BackgroundJobsBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<BackgroundJobRecord>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
});
}
}
}

@ -12,8 +12,6 @@ namespace Volo.Abp.BackgroundJobs.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
BackgroundJobsBsonClassMap.Configure();
context.Services.AddMongoDbContext<BackgroundJobsMongoDbContext>(options =>
{
options.AddRepository<BackgroundJobRecord, MongoBackgroundJobRepository>();

@ -1,48 +0,0 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.MongoDB;
using Volo.Abp.Threading;
using Volo.Blogging.Blogs;
using Volo.Blogging.Comments;
using Volo.Blogging.Posts;
using Volo.Blogging.Tagging;
using Volo.Blogging.Users;
namespace Volo.Blogging.MongoDB
{
public static class AbpBloggingBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<BlogUser>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<Blog>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<Post>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<Comment>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<Tag>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
});
}
}
}

@ -17,8 +17,6 @@ namespace Volo.Blogging.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpBloggingBsonClassMap.Configure();
context.Services.AddMongoDbContext<BloggingMongoDbContext>(options =>
{
options.AddRepository<Blog, MongoBlogRepository>();

@ -1,35 +0,0 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.MongoDB;
using Volo.Abp.Threading;
namespace Volo.Abp.Identity.MongoDB
{
public static class AbpIdentityBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<IdentityUser>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<IdentityRole>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<IdentityClaimType>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
});
}
}
}

@ -12,8 +12,6 @@ namespace Volo.Abp.Identity.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpIdentityBsonClassMap.Configure();
context.Services.AddMongoDbContext<AbpIdentityMongoDbContext>(options =>
{
options.AddRepository<IdentityUser, MongoIdentityUserRepository>();

@ -1,42 +0,0 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Grants;
using Volo.Abp.IdentityServer.IdentityResources;
using Volo.Abp.MongoDB;
using Volo.Abp.Threading;
namespace Volo.Abp.IdentityServer.MongoDB
{
public class AbpIdentityServerBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<ApiResource>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<Client>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<IdentityResource>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
BsonClassMap.RegisterClassMap<PersistedGrant>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
});
}
}
}

@ -16,8 +16,6 @@ namespace Volo.Abp.IdentityServer.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpIdentityServerBsonClassMap.Configure();
context.Services.AddMongoDbContext<AbpIdentityServerMongoDbContext>(options =>
{
options.AddRepository<ApiResource, MongoApiResourceRepository>();

@ -1,21 +0,0 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.Threading;
namespace Volo.Abp.PermissionManagement.MongoDB
{
public static class AbpPermissionManagementBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<PermissionGrant>(map =>
{
map.AutoMap();
});
});
}
}
}

@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;
using Volo.Abp.Modularity;
using Volo.Abp.MongoDB;
@ -13,8 +12,6 @@ namespace Volo.Abp.PermissionManagement.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpPermissionManagementBsonClassMap.Configure();
context.Services.AddMongoDbContext<PermissionManagementMongoDbContext>(options =>
{
options.AddDefaultRepositories<IPermissionManagementMongoDbContext>();

@ -1,21 +0,0 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.Threading;
namespace Volo.Abp.SettingManagement.MongoDB
{
public static class AbpSettingManagementBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<Setting>(map =>
{
map.AutoMap();
});
});
}
}
}

@ -12,8 +12,6 @@ namespace Volo.Abp.SettingManagement.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpSettingManagementBsonClassMap.Configure();
context.Services.AddMongoDbContext<SettingManagementMongoDbContext>(options =>
{
options.AddDefaultRepositories<ISettingManagementMongoDbContext>();

@ -1,23 +0,0 @@
using MongoDB.Bson.Serialization;
using Volo.Abp.MongoDB;
using Volo.Abp.Threading;
namespace Volo.Abp.TenantManagement.MongoDb
{
public static class AbpTenantManagementBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
BsonClassMap.RegisterClassMap<Tenant>(map =>
{
map.AutoMap();
map.ConfigureExtraProperties();
});
});
}
}
}

@ -12,8 +12,6 @@ namespace Volo.Abp.TenantManagement.MongoDb
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
AbpTenantManagementBsonClassMap.Configure();
context.Services.AddMongoDbContext<TenantManagementMongoDbContext>(options =>
{
options.AddDefaultRepositories<ITenantManagementMongoDbContext>();

@ -1,21 +0,0 @@
using Volo.Abp.Threading;
namespace MyCompanyName.MyProjectName.MongoDB
{
public static class MyProjectNameBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
//Register mappings here. Example:
//BsonClassMap.RegisterClassMap<Question>(map =>
//{
// map.AutoMap();
//});
});
}
}
}

@ -12,8 +12,6 @@ namespace MyCompanyName.MyProjectName.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
MyProjectNameBsonClassMap.Configure();
context.Services.AddMongoDbContext<MyProjectNameMongoDbContext>(options =>
{
/* Add custom repositories here. Example:

@ -1,21 +0,0 @@
using Volo.Abp.Threading;
namespace MyCompanyName.MyProjectName.MongoDB
{
public static class MyProjectNameBsonClassMap
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
//Register mappings here. Example:
//BsonClassMap.RegisterClassMap<Question>(map =>
//{
// map.AutoMap();
//});
});
}
}
}

@ -12,8 +12,6 @@ namespace MyCompanyName.MyProjectName.MongoDB
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
MyProjectNameBsonClassMap.Configure();
context.Services.AddMongoDbContext<MyProjectNameMongoDbContext>(options =>
{
/* Add custom repositories here. Example:

Loading…
Cancel
Save