Skip to content

Commit

Permalink
Merge pull request #19625 from abpframework/nolayers
Browse files Browse the repository at this point in the history
Add GlobalFeatureConfigurator and ModuleExtensionConfigurator to nolayers template
  • Loading branch information
realLiangshiwei authored May 15, 2024
2 parents 47d1f1d + 789badd commit 9894061
Show file tree
Hide file tree
Showing 30 changed files with 808 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Volo.Abp.Threading;

namespace MyCompanyName.MyProjectName;

public static class MyProjectNameGlobalFeatureConfigurator
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure (enable/disable) global features of the used modules here.
* Please refer to the documentation to learn more about the Global Features System:
* https://docs.abp.io/en/abp/latest/Global-Features
*/
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
{
options.IsBlazorWebApp = true;
});

MyProjectNameGlobalFeatureConfigurator.Configure();
MyProjectNameModuleExtensionConfigurator.Configure();
}

public override void ConfigureServices(ServiceConfigurationContext context)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Volo.Abp.Threading;

namespace MyCompanyName.MyProjectName;

public static class MyProjectNameModuleExtensionConfigurator
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

public static void Configure()
{
OneTimeRunner.Run(() =>
{
ConfigureExistingProperties();
ConfigureExtraProperties();
});
}

private static void ConfigureExistingProperties()
{
/* You can change max lengths for properties of the
* entities defined in the modules used by your application.
*
* Example: Change user and role name max lengths
AbpUserConsts.MaxNameLength = 99;
IdentityRoleConsts.MaxNameLength = 99;
* Notice: It is not suggested to change property lengths
* unless you really need it. Go with the standard values wherever possible.
*
* If you are using EF Core, you will need to run the add-migration command after your changes.
*/
}

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/abp/latest/Module-Entity-Extensions
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public MyProjectNameDbContext CreateDbContext(string[] args)
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
//</TEMPLATE-REMOVE>
MyProjectNameEfCoreEntityExtensionMappings.Configure();

var configuration = BuildConfiguration();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Volo.Abp.Threading;

namespace MyCompanyName.MyProjectName.Data;

public static class MyProjectNameEfCoreEntityExtensionMappings
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

public static void Configure()
{
MyProjectNameGlobalFeatureConfigurator.Configure();
MyProjectNameModuleExtensionConfigurator.Configure();

OneTimeRunner.Run(() =>
{
/* You can configure extra properties for the
* entities defined in the modules used by your application.
*
* This class can be used to map these extra properties to table fields in the database.
*
* USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING.
* USE MyProjectNameModuleExtensionConfigurator CLASS (in the Domain.Shared project)
* FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES
*
* Example: Map a property to a table field:
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, string>(
"MyProperty",
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasMaxLength(128);
}
);
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Volo.Abp.Threading;

namespace MyCompanyName.MyProjectName;

public static class MyProjectNameGlobalFeatureConfigurator
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure (enable/disable) global features of the used modules here.
* Please refer to the documentation to learn more about the Global Features System:
* https://docs.abp.io/en/abp/latest/Global-Features
*/
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
{
options.IsBlazorWebApp = true;
});

MyProjectNameGlobalFeatureConfigurator.Configure();
MyProjectNameModuleExtensionConfigurator.Configure();
MyProjectNameEfCoreEntityExtensionMappings.Configure();
}

public override void ConfigureServices(ServiceConfigurationContext context)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Volo.Abp.Threading;

namespace MyCompanyName.MyProjectName;

public static class MyProjectNameModuleExtensionConfigurator
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

public static void Configure()
{
OneTimeRunner.Run(() =>
{
ConfigureExistingProperties();
ConfigureExtraProperties();
});
}

private static void ConfigureExistingProperties()
{
/* You can change max lengths for properties of the
* entities defined in the modules used by your application.
*
* Example: Change user and role name max lengths
AbpUserConsts.MaxNameLength = 99;
IdentityRoleConsts.MaxNameLength = 99;
* Notice: It is not suggested to change property lengths
* unless you really need it. Go with the standard values wherever possible.
*
* If you are using EF Core, you will need to run the add-migration command after your changes.
*/
}

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/abp/latest/Module-Entity-Extensions
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public MyProjectNameDbContext CreateDbContext(string[] args)
// https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
//</TEMPLATE-REMOVE>

MyProjectNameEfCoreEntityExtensionMappings.Configure();

var configuration = BuildConfiguration();

var builder = new DbContextOptionsBuilder<MyProjectNameDbContext>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Volo.Abp.Threading;

namespace MyCompanyName.MyProjectName.Data;

public static class MyProjectNameEfCoreEntityExtensionMappings
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

public static void Configure()
{
MyProjectNameGlobalFeatureConfigurator.Configure();
MyProjectNameModuleExtensionConfigurator.Configure();

OneTimeRunner.Run(() =>
{
/* You can configure extra properties for the
* entities defined in the modules used by your application.
*
* This class can be used to map these extra properties to table fields in the database.
*
* USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING.
* USE MyProjectNameModuleExtensionConfigurator CLASS (in the Domain.Shared project)
* FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES
*
* Example: Map a property to a table field:
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, string>(
"MyProperty",
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasMaxLength(128);
}
);
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
serverBuilder.AddProductionEncryptionAndSigningCertificate("openiddict.pfx", "00000000-0000-0000-0000-000000000000");
});
}

MyProjectNameEfCoreEntityExtensionMappings.Configure();
}

public override void ConfigureServices(ServiceConfigurationContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace MyCompanyName.MyProjectName;
)]
public class MyProjectNameContractsModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
MyProjectNameGlobalFeatureConfigurator.Configure();
MyProjectNameModuleExtensionConfigurator.Configure();
}

public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Volo.Abp.Threading;

namespace MyCompanyName.MyProjectName;

public static class MyProjectNameGlobalFeatureConfigurator
{
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

public static void Configure()
{
OneTimeRunner.Run(() =>
{
/* You can configure (enable/disable) global features of the used modules here.
* Please refer to the documentation to learn more about the Global Features System:
* https://docs.abp.io/en/abp/latest/Global-Features
*/
});
}
}
Loading

0 comments on commit 9894061

Please sign in to comment.