Browse Source

Configure extra properties in the startup template

pull/5130/head
Halil İbrahim Kalkan 6 years ago
parent
commit
c9de97ad33
  1. 3
      docs/en/Module-Entity-Extensions.md
  2. 2
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameDomainSharedModule.cs
  3. 39
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameModuleExtensionConfigurator.cs
  4. 6
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/MyProjectNameDomainModule.cs
  5. 32
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/ObjectExtending/MyProjectNameDomainObjectExtensions.cs
  6. 35
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameEfCoreEntityExtensionMappings.cs

3
docs/en/Module-Entity-Extensions.md

@ -0,0 +1,3 @@
# Module Entity Extensions
See https://docs.abp.io/en/commercial/latest/guides/module-entity-extensions (it will be moved here soon).

2
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameDomainSharedModule.cs

@ -29,7 +29,7 @@ namespace MyCompanyName.MyProjectName
{ {
public override void PreConfigureServices(ServiceConfigurationContext context) public override void PreConfigureServices(ServiceConfigurationContext context)
{ {
MyProjectNameModulePropertyConfigurator.Configure(); MyProjectNameModuleExtensionConfigurator.Configure();
} }
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)

39
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameModuleExtensionConfigurator.cs

@ -1,11 +1,11 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading; using Volo.Abp.Threading;
namespace MyCompanyName.MyProjectName namespace MyCompanyName.MyProjectName
{ {
public static class MyProjectNameModulePropertyConfigurator public static class MyProjectNameModuleExtensionConfigurator
{ {
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
@ -14,6 +14,7 @@ namespace MyCompanyName.MyProjectName
OneTimeRunner.Run(() => OneTimeRunner.Run(() =>
{ {
ConfigureExistingProperties(); ConfigureExistingProperties();
ConfigureExtraProperties();
}); });
} }
@ -31,5 +32,39 @@ namespace MyCompanyName.MyProjectName
* unless you really need it. Go with the standard values wherever possible. * unless you really need it. Go with the standard values wherever possible.
*/ */
} }
private static void ConfigureExtraProperties()
{
/* You can configure extra properties for the
* entities defined in the modules used by your application.
*
* This class can be used to define these extra properties
* with a high level, easy to use API.
*
* Example: Add a new property to the user entity of the identity module
ObjectExtensionManager.Instance.Modules()
.ConfigureIdentity(identity =>
{
identity.ConfigureUser(user =>
{
user.AddOrUpdateProperty<string>( //property type: string
"SocialSecurityNumber", //property name
property =>
{
//validation rules
property.Attributes.Add(new RequiredAttribute());
property.Attributes.Add(new StringLengthAttribute(64) {MinimumLength = 4});
//...other configurations for this property
}
);
});
});
* See the documentation for more:
* https://docs.abp.io/en/latest/Module-Entity-Extensions
*/
}
} }
} }

6
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/MyProjectNameDomainModule.cs

@ -1,7 +1,6 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using MyCompanyName.MyProjectName.MultiTenancy; using MyCompanyName.MyProjectName.MultiTenancy;
using MyCompanyName.MyProjectName.ObjectExtending;
using Volo.Abp.AuditLogging; using Volo.Abp.AuditLogging;
using Volo.Abp.BackgroundJobs; using Volo.Abp.BackgroundJobs;
using Volo.Abp.Emailing; using Volo.Abp.Emailing;
@ -32,11 +31,6 @@ namespace MyCompanyName.MyProjectName
)] )]
public class MyProjectNameDomainModule : AbpModule public class MyProjectNameDomainModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context)
{
MyProjectNameDomainObjectExtensions.Configure();
}
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
Configure<AbpMultiTenancyOptions>(options => Configure<AbpMultiTenancyOptions>(options =>

32
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/ObjectExtending/MyProjectNameDomainObjectExtensions.cs

@ -1,32 +0,0 @@
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;
namespace MyCompanyName.MyProjectName.ObjectExtending
{
public static class MyProjectNameDomainObjectExtensions
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure extension properties to entities or other object types
* defined in the depended modules.
*
* If you are using EF Core and want to map the entity extension properties to new
* table fields in the database, then configure them in the MyProjectNameEfCoreEntityExtensionMappings
*
* Example:
*
* ObjectExtensionManager.Instance
* .AddOrUpdateProperty<IdentityRole, string>("Title");
*
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Object-Extensions
*/
});
}
}
}

35
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.EntityFrameworkCore/EntityFrameworkCore/MyProjectNameEfCoreEntityExtensionMappings.cs

@ -1,4 +1,5 @@
using Volo.Abp.Identity; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading; using Volo.Abp.Threading;
@ -10,26 +11,30 @@ namespace MyCompanyName.MyProjectName.EntityFrameworkCore
public static void Configure() public static void Configure()
{ {
MyProjectNameModulePropertyConfigurator.Configure(); MyProjectNameModuleExtensionConfigurator.Configure();
OneTimeRunner.Run(() => OneTimeRunner.Run(() =>
{ {
/* You can configure entity extension properties for the /* You can configure extra properties for the
* entities defined in the used modules. * entities defined in the modules used by your application.
* *
* The properties defined here becomes table fields. * This class can be used to map these extra properties to table fields in the database.
* If you want to use the ExtraProperties dictionary of the entity
* instead of creating a new field, then define the property in the
* MyProjectNameDomainObjectExtensions class.
* *
* Example: * USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING.
* * USE MyProjectNameModuleExtensionConfigurator CLASS (in the Domain.Shared project)
* ObjectExtensionManager.Instance * FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES
* .MapEfCoreProperty<IdentityUser, string>(
* "MyProperty",
* b => b.HasMaxLength(128)
* );
* *
* Example: Map a property to a table field:
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, string>(
"MyProperty",
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasMaxLength(128);
}
);
* See the documentation for more: * See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities * https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/ */

Loading…
Cancel
Save