From 71b573bf60f49a10be6cdd6c0230c965192328e0 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Wed, 26 Dec 2018 17:54:28 +0300 Subject: [PATCH] Resolved #694: Auto configure defaults for entities for mongodb. --- docs/en/Best-Practices/MongoDB-Integration.md | 30 -------- docs/en/Entity-Framework-Core.md | 38 ++++++--- docs/en/MongoDB.md | 77 +++++++++++++++---- .../Abp/MongoDB/AbpBsonClassMapExtensions.cs | 33 +++++++- .../Volo/Abp/MongoDB/AbpGlobalBsonClassMap.cs | 60 --------------- .../Volo/Abp/MongoDB/IHasBsonClassMap.cs | 9 +++ .../Abp/MongoDB/IMongoEntityModelBuilder.cs | 23 ++++++ .../Volo/Abp/MongoDB/IMongoModelBuilder.cs | 6 +- .../Abp/MongoDB/MongoEntityModelBuilder.cs | 23 +++++- .../Volo/Abp/MongoDB/MongoModelBuilder.cs | 49 +++++++++--- .../Volo/Abp/MongoDB/MongoModelSource.cs | 2 - .../MongoDB/AbpAuditLoggingBsonClassMap.cs | 21 ----- .../MongoDB/AbpAuditLoggingMongoDbModule.cs | 2 - .../MongoDB/BackgroundJobsBsonClassMap.cs | 23 ------ .../MongoDB/BackgroundJobsMongoDbModule.cs | 2 - .../MongoDB/AbpBloggingBsonClassMap.cs | 48 ------------ .../Blogging/MongoDB/BloggingMongoDbModule.cs | 2 - .../MongoDB/AbpIdentityBsonClassMap.cs | 35 --------- .../MongoDB/AbpIdentityMongoDbModule.cs | 2 - .../MongoDB/AbpIdentityServerBsonClassMap.cs | 42 ---------- .../MongoDB/AbpIdentityServerMongoDbModule.cs | 2 - .../AbpPermissionManagementBsonClassMap.cs | 21 ----- .../AbpPermissionManagementMongoDbModule.cs | 3 - .../AbpSettingManagementBsonClassMap.cs | 21 ----- .../AbpSettingManagementMongoDbModule.cs | 2 - .../AbpTenantManagementBsonClassMap.cs | 23 ------ .../AbpTenantManagementMongoDbModule.cs | 2 - .../MongoDB/MyProjectNameBsonClassMap.cs | 21 ----- .../MongoDB/MyProjectNameMongoDbModule.cs | 2 - .../MongoDB/MyProjectNameBsonClassMap.cs | 21 ----- .../MongoDB/MyProjectNameMongoDbModule.cs | 2 - 31 files changed, 206 insertions(+), 441 deletions(-) delete mode 100644 framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpGlobalBsonClassMap.cs create mode 100644 framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IHasBsonClassMap.cs create mode 100644 framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoEntityModelBuilder.cs delete mode 100644 modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingBsonClassMap.cs delete mode 100644 modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsBsonClassMap.cs delete mode 100644 modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/AbpBloggingBsonClassMap.cs delete mode 100644 modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs delete mode 100644 modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerBsonClassMap.cs delete mode 100644 modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/AbpPermissionManagementBsonClassMap.cs delete mode 100644 modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/AbpSettingManagementBsonClassMap.cs delete mode 100644 modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/AbpTenantManagementBsonClassMap.cs delete mode 100644 templates/module/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameBsonClassMap.cs delete mode 100644 templates/service/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameBsonClassMap.cs diff --git a/docs/en/Best-Practices/MongoDB-Integration.md b/docs/en/Best-Practices/MongoDB-Integration.md index 32eefadd6a..76b6e8561f 100644 --- a/docs/en/Best-Practices/MongoDB-Integration.md +++ b/docs/en/Best-Practices/MongoDB-Integration.md @@ -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(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - - BsonClassMap.RegisterClassMap(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` 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(options => { options.AddRepository(); diff --git a/docs/en/Entity-Framework-Core.md b/docs/en/Entity-Framework-Core.md index 4f9ff367ee..e608736bcd 100644 --- a/docs/en/Entity-Framework-Core.md +++ b/docs/en/Entity-Framework-Core.md @@ -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` 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 +{ + +} +``` + +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, 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` 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(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, 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: diff --git a/docs/en/MongoDB.md b/docs/en/MongoDB.md index c03c6f4f2c..e7d8084f41 100644 --- a/docs/en/MongoDB.md +++ b/docs/en/MongoDB.md @@ -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(b => - { - b.CollectionName = "Questions"; - }); + base.CreateModel(modelBuilder); + + //Customize the configuration for your collections. } } ``` * It's derived from `AbpMongoDbContext` class. * Adds a public `IMongoCollection` 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` 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(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 Questions => Collection(); +```` + +### 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` 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(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: diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpBsonClassMapExtensions.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpBsonClassMapExtensions.cs index 68a2719c38..f53e524914 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpBsonClassMapExtensions.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpBsonClassMapExtensions.cs @@ -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(this BsonClassMap map) - where T : class, IHasExtraProperties + public static void ConfigureAbpConventions(this BsonClassMap map) + { + map.AutoMap(); + map.ConfigureExtraProperties(); + } + + public static void ConfigureExtraProperties(this BsonClassMap map) + where TEntity : class, IHasExtraProperties { map.SetExtraElementsMember(new BsonMemberMap( map, - typeof(T).GetMember(nameof(IHasExtraProperties.ExtraProperties))[0]) + typeof(TEntity).GetMember(nameof(IHasExtraProperties.ExtraProperties))[0]) ); } + + /// + /// Configures SetExtraElementsMember if the + /// implements the interface. + /// Otherwise, does nothing + /// + public static void ConfigureExtraProperties(this BsonClassMap map) + { + if (map.ClassType.IsAssignableTo()) + { + map.SetExtraElementsMember( + new BsonMemberMap( + map, + map.ClassType.GetMember(nameof(IHasExtraProperties.ExtraProperties))[0] + ) + ); + } + } } } diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpGlobalBsonClassMap.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpGlobalBsonClassMap.cs deleted file mode 100644 index db74e1dae8..0000000000 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/AbpGlobalBsonClassMap.cs +++ /dev/null @@ -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 PreConfiguredTypes = new HashSet(); - - /// - /// Configure default/base properties for the entity using . - /// This method runs single time for an for the application lifetime. - /// Subsequent calls has no effect for the same . - /// - public static void ConfigureDefaults() - { - ConfigureDefaults(typeof(TEntity)); - } - - /// - /// Configure default/base properties for the entity using . - /// This method runs single time for an for the application lifetime. - /// Subsequent calls has no effect for the same . - /// - 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()) - { - map.SetExtraElementsMember( - new BsonMemberMap( - map, - entityType.GetMember(nameof(IHasExtraProperties.ExtraProperties))[0] - ) - ); - } - - BsonClassMap.RegisterClassMap(map); - } - } -} diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IHasBsonClassMap.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IHasBsonClassMap.cs new file mode 100644 index 0000000000..86ea29d744 --- /dev/null +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IHasBsonClassMap.cs @@ -0,0 +1,9 @@ +using MongoDB.Bson.Serialization; + +namespace Volo.Abp.MongoDB +{ + public interface IHasBsonClassMap + { + BsonClassMap GetMap(); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoEntityModelBuilder.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoEntityModelBuilder.cs new file mode 100644 index 0000000000..4e02386b13 --- /dev/null +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoEntityModelBuilder.cs @@ -0,0 +1,23 @@ +using System; +using MongoDB.Bson.Serialization; + +namespace Volo.Abp.MongoDB +{ + public interface IMongoEntityModelBuilder + { + Type EntityType { get; } + + string CollectionName { get; set; } + + BsonClassMap BsonMap { get; } + } + + public interface IMongoEntityModelBuilder + { + Type EntityType { get; } + + string CollectionName { get; set; } + + BsonClassMap BsonMap { get; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoModelBuilder.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoModelBuilder.cs index f10bb26f58..eb837c4765 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoModelBuilder.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/IMongoModelBuilder.cs @@ -6,10 +6,10 @@ namespace Volo.Abp.MongoDB { public interface IMongoModelBuilder { - void Entity([NotNull] Action buildAction); + void Entity(Action> buildAction = null); - void Entity([NotNull] Type entityType, [NotNull] Action buildAction); + void Entity([NotNull] Type entityType, Action buildAction = null); - IReadOnlyList GetEntities(); + IReadOnlyList GetEntities(); } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoEntityModelBuilder.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoEntityModelBuilder.cs index 028ce84cde..7540342643 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoEntityModelBuilder.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoEntityModelBuilder.cs @@ -1,18 +1,33 @@ +using MongoDB.Bson.Serialization; using System; namespace Volo.Abp.MongoDB { - public class MongoEntityModelBuilder : IMongoEntityModel + public class MongoEntityModelBuilder : + IMongoEntityModel, + IHasBsonClassMap, + IMongoEntityModelBuilder, + IMongoEntityModelBuilder { public Type EntityType { get; } public string CollectionName { get; set; } - public MongoEntityModelBuilder(Type entityType) + BsonClassMap IMongoEntityModelBuilder.BsonMap => _bsonClassMap; + BsonClassMap IMongoEntityModelBuilder.BsonMap => _bsonClassMap; + + private readonly BsonClassMap _bsonClassMap; + + public MongoEntityModelBuilder() { - Check.NotNull(entityType, nameof(entityType)); + EntityType = typeof(TEntity); + _bsonClassMap = new BsonClassMap(); + _bsonClassMap.ConfigureAbpConventions(); + } - EntityType = entityType; + public BsonClassMap GetMap() + { + return _bsonClassMap; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelBuilder.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelBuilder.cs index 7550cf7c6b..788d0bdbea 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelBuilder.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelBuilder.cs @@ -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 _entityModelBuilders; + private readonly Dictionary _entityModelBuilders; + + private static readonly object SyncObj = new object(); public MongoModelBuilder() { - _entityModelBuilders = new Dictionary(); + _entityModelBuilders = new Dictionary(); } public MongoDbContextModel Build() { var entityModels = _entityModelBuilders .Select(x => x.Value) - .ToImmutableDictionary(x => x.EntityType, x => (IMongoEntityModel) x); + .Cast() + .ToImmutableDictionary(x => x.EntityType, x => x); + + foreach (var entityModel in entityModels.Values) + { + var map = entityModel.As().GetMap(); + lock (SyncObj) + { + if (!BsonClassMap.IsClassMapRegistered(map.ClassType)) + { + BsonClassMap.RegisterClassMap(map); + } + } + } return new MongoDbContextModel(entityModels); } - public virtual void Entity([NotNull] Action buildAction) + public virtual void Entity(Action> buildAction = null) { - Entity(typeof(TEntity), buildAction); + var model = (IMongoEntityModelBuilder)_entityModelBuilders.GetOrAdd( + typeof(TEntity), + () => new MongoEntityModelBuilder() + ); + + buildAction?.Invoke(model); } - public virtual void Entity([NotNull] Type entityType, [NotNull] Action buildAction) + public virtual void Entity(Type entityType, Action 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 GetEntities() + public virtual IReadOnlyList GetEntities() { - return _entityModelBuilders.Values.ToImmutableList(); + return _entityModelBuilders.Values.Cast().ToImmutableList(); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelSource.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelSource.cs index 1ae6aeb124..c5cb0da1c8 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelSource.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/MongoDB/MongoModelSource.cs @@ -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) diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingBsonClassMap.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingBsonClassMap.cs deleted file mode 100644 index cb8fa2eb67..0000000000 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingBsonClassMap.cs +++ /dev/null @@ -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(map => - { - map.AutoMap(); - }); - }); - } - } -} diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs index bebf04f83f..e73e3642b7 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/AbpAuditLoggingMongoDbModule.cs @@ -10,8 +10,6 @@ namespace Volo.Abp.AuditLogging.MongoDB { public override void ConfigureServices(ServiceConfigurationContext context) { - AbpAuditLoggingBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { options.AddRepository(); diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsBsonClassMap.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsBsonClassMap.cs deleted file mode 100644 index 7dbdd0f96f..0000000000 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsBsonClassMap.cs +++ /dev/null @@ -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(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - }); - } - } -} \ No newline at end of file diff --git a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbModule.cs b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbModule.cs index c233892b2d..6ace195fa5 100644 --- a/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbModule.cs +++ b/modules/background-jobs/src/Volo.Abp.BackgroundJobs.MongoDB/Volo/Abp/BackgroundJobs/MongoDB/BackgroundJobsMongoDbModule.cs @@ -12,8 +12,6 @@ namespace Volo.Abp.BackgroundJobs.MongoDB { public override void ConfigureServices(ServiceConfigurationContext context) { - BackgroundJobsBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { options.AddRepository(); diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/AbpBloggingBsonClassMap.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/AbpBloggingBsonClassMap.cs deleted file mode 100644 index 589b96b765..0000000000 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/AbpBloggingBsonClassMap.cs +++ /dev/null @@ -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(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - }); - } - } -} diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbModule.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbModule.cs index e68d0d9b71..1991c4d958 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbModule.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbModule.cs @@ -17,8 +17,6 @@ namespace Volo.Blogging.MongoDB { public override void ConfigureServices(ServiceConfigurationContext context) { - AbpBloggingBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { options.AddRepository(); diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs deleted file mode 100644 index d55ad6ee41..0000000000 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityBsonClassMap.cs +++ /dev/null @@ -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(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - }); - } - } -} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbModule.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbModule.cs index e88fab8a2d..cfbc10adba 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbModule.cs @@ -12,8 +12,6 @@ namespace Volo.Abp.Identity.MongoDB { public override void ConfigureServices(ServiceConfigurationContext context) { - AbpIdentityBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { options.AddRepository(); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerBsonClassMap.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerBsonClassMap.cs deleted file mode 100644 index 5128aee20a..0000000000 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerBsonClassMap.cs +++ /dev/null @@ -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(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - BsonClassMap.RegisterClassMap(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - }); - } - } -} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs index 599f60f579..3e96a2f0bc 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs @@ -16,8 +16,6 @@ namespace Volo.Abp.IdentityServer.MongoDB { public override void ConfigureServices(ServiceConfigurationContext context) { - AbpIdentityServerBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { options.AddRepository(); diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/AbpPermissionManagementBsonClassMap.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/AbpPermissionManagementBsonClassMap.cs deleted file mode 100644 index 707aa66365..0000000000 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/AbpPermissionManagementBsonClassMap.cs +++ /dev/null @@ -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(map => - { - map.AutoMap(); - }); - }); - } - } -} \ No newline at end of file diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/AbpPermissionManagementMongoDbModule.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/AbpPermissionManagementMongoDbModule.cs index 16cc9b3bc6..8b294c3796 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/AbpPermissionManagementMongoDbModule.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.MongoDB/Volo/Abp/PermissionManagement/MongoDb/AbpPermissionManagementMongoDbModule.cs @@ -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(options => { options.AddDefaultRepositories(); diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/AbpSettingManagementBsonClassMap.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/AbpSettingManagementBsonClassMap.cs deleted file mode 100644 index a816809761..0000000000 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/AbpSettingManagementBsonClassMap.cs +++ /dev/null @@ -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(map => - { - map.AutoMap(); - }); - }); - } - } -} \ No newline at end of file diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/AbpSettingManagementMongoDbModule.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/AbpSettingManagementMongoDbModule.cs index 2eafba45ab..b2d4c1852b 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/AbpSettingManagementMongoDbModule.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.MongoDB/Volo/Abp/SettingManagement/MongoDB/AbpSettingManagementMongoDbModule.cs @@ -12,8 +12,6 @@ namespace Volo.Abp.SettingManagement.MongoDB { public override void ConfigureServices(ServiceConfigurationContext context) { - AbpSettingManagementBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { options.AddDefaultRepositories(); diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/AbpTenantManagementBsonClassMap.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/AbpTenantManagementBsonClassMap.cs deleted file mode 100644 index f5a693bb65..0000000000 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/AbpTenantManagementBsonClassMap.cs +++ /dev/null @@ -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(map => - { - map.AutoMap(); - map.ConfigureExtraProperties(); - }); - }); - } - } -} \ No newline at end of file diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/AbpTenantManagementMongoDbModule.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/AbpTenantManagementMongoDbModule.cs index 040f0f7805..4d0ca1621f 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/AbpTenantManagementMongoDbModule.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.MongoDB/Volo/Abp/TenantManagement/MongoDb/AbpTenantManagementMongoDbModule.cs @@ -12,8 +12,6 @@ namespace Volo.Abp.TenantManagement.MongoDb { public override void ConfigureServices(ServiceConfigurationContext context) { - AbpTenantManagementBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { options.AddDefaultRepositories(); diff --git a/templates/module/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameBsonClassMap.cs b/templates/module/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameBsonClassMap.cs deleted file mode 100644 index af452456d9..0000000000 --- a/templates/module/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameBsonClassMap.cs +++ /dev/null @@ -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(map => - //{ - // map.AutoMap(); - //}); - }); - } - } -} \ No newline at end of file diff --git a/templates/module/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameMongoDbModule.cs b/templates/module/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameMongoDbModule.cs index b3e21b43da..453806b057 100644 --- a/templates/module/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameMongoDbModule.cs +++ b/templates/module/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameMongoDbModule.cs @@ -12,8 +12,6 @@ namespace MyCompanyName.MyProjectName.MongoDB { public override void ConfigureServices(ServiceConfigurationContext context) { - MyProjectNameBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { /* Add custom repositories here. Example: diff --git a/templates/service/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameBsonClassMap.cs b/templates/service/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameBsonClassMap.cs deleted file mode 100644 index af452456d9..0000000000 --- a/templates/service/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameBsonClassMap.cs +++ /dev/null @@ -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(map => - //{ - // map.AutoMap(); - //}); - }); - } - } -} \ No newline at end of file diff --git a/templates/service/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameMongoDbModule.cs b/templates/service/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameMongoDbModule.cs index b3e21b43da..453806b057 100644 --- a/templates/service/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameMongoDbModule.cs +++ b/templates/service/src/MyCompanyName.MyProjectName.MongoDB/MyCompanyName/MyProjectName/MongoDB/MyProjectNameMongoDbModule.cs @@ -12,8 +12,6 @@ namespace MyCompanyName.MyProjectName.MongoDB { public override void ConfigureServices(ServiceConfigurationContext context) { - MyProjectNameBsonClassMap.Configure(); - context.Services.AddMongoDbContext(options => { /* Add custom repositories here. Example: