- Template: app
- Created ABP Studio Version: 2.1.2
- Current ABP Studio Version: 2.1.2
- Tiered: No
- Multi-Tenancy: Yes
- UI Framework: blazor-webapp
- Theme: leptonx
- Theme Style: system
- Theme Menu Placement: side
- Run Install Libs: No
- Database Provider: ef
- Database Management System: postgresql
- Separate Tenant Schema: No
- Mobile Framework: maui
- Public Website: Yes
- Social Login: Yes
- Include Tests: Yes
- Kubernetes Configuration: Yes
- Distributed Event Bus: rabbitmq
- Use Local References: No
- Optional Modules:
- GDPR
- FileManagement
- TextTemplateManagement
- LanguageManagement
- AuditLogging
- Chat
- OpenIddictAdmin
- Selected Languages: Arabic, Chinese (Simplified), Chinese (Traditional), English, English (United Kingdom), French, German (Germany), Hindi , Italian, Russian, Spanish
- Default Language: Arabic
- Create Command: abp new Jdoe.Pci -t app --ui-framework blazor-webapp --mobile maui --database-provider ef --database-management-system postgresql --theme leptonx --skip-migration --skip-migrator --public-website --without-cms-kit --sample-crud-page --dont-run-install-libs --dont-run-bundling -chat -file-management
I can see there is a property as ExtraProperties in the AbpUser but there is no end point to update that property. I wonder what its purpose and how I can add value in there? I can see its marked as readonly when getting user
4 Answer(s)
-
0
hi
See: https://abp.io/docs/latest/framework/fundamentals/object-extensions https://abp.io/docs/latest/framework/architecture/modularity/extending/customizing-application-modules-extending-entities
-
0
thanks. does it mean at the moment there is no way to add/update these ExtraProperties on the AbpUser and I have to define my own Api to add/update values for this?
-
0
- Solution
You do not need to create your own API just to use
ExtraPropertiesonAbpUser(IdentityUser).ABP already wires
ExtraPropertiesinto the existing Identity user endpoints:POST /api/identity/users→IdentityUserCreateDtoPUT /api/identity/users/{id}→IdentityUserUpdateDto
Both DTOs inherit from
ExtensibleObject, and inIdentityUserAppServicethey are mapped to the entity like this:// Create input.MapExtraPropertiesTo(user); // Update input.MapExtraPropertiesTo(user);So the flow is:
Define the extra properties on IdentityUser (required!)
In your
*.Domain.Sharedproject, usually inYourProjectModuleExtensionConfigurator.ConfigureExtraProperties():
using System.ComponentModel.DataAnnotations; using Volo.Abp.ObjectExtending; using Volo.Abp.Identity; public static class YourProjectModuleExtensionConfigurator { private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); public static void Configure() { ConfigureExtraProperties(); } private static void ConfigureExtraProperties() { OneTimeRunner.Run(() => { ObjectExtensionManager.Instance .Modules() .ConfigureIdentity(identity => { identity.ConfigureUser(user => { user.AddOrUpdateProperty<string>( "MyCustomCode", options => { options.Attributes.Add(new RequiredAttribute()); options.Attributes.Add(new StringLengthAttribute(64)); }); }); }); }); } }Optionally, if you want a column instead of JSON-only storage, map it in your
*.EntityFrameworkCoreproject (YourProjectEfCoreEntityExtensionMappings):using Volo.Abp.Identity; using Volo.Abp.ObjectExtending; OneTimeRunner.Run(() => { ObjectExtensionManager.Instance .MapEfCoreProperty<IdentityUser, string>( "MyCustomCode", (entityBuilder, propertyBuilder) => { propertyBuilder.HasMaxLength(64); }); });Then add a migration/update the DB.
Send values via existing Identity endpoints
Once the module entity extension is configured, you can create/update users by sending
extraPropertiesin the JSON body:Create:
POST /api/identity/users { "userName": "jdoe", "email": "jdoe@test.com", "password": "1q2w3E*", "name": "John", "surname": "Doe", "isActive": true, "lockoutEnabled": false, "roleNames": [], "extraProperties": { "MyCustomCode": "ABC-123" } }Update:
PUT /api/identity/users/{id} { "userName": "jdoe", "email": "jdoe@test.com", "name": "John", "surname": "Doe", "isActive": true, "lockoutEnabled": false, "roleNames": [], "concurrencyStamp": "....", "extraProperties": { "MyCustomCode": "XYZ-999" } }Even if Swagger shows
extraPropertieson the output DTO as read-only, the input DTOs still accept it andMapExtraPropertiesToapplies those values to theIdentityUser.ExtraPropertiesdictionary.Using ExtraProperties in code (optional)
From domain/application code you can also work directly with the entity’s extra properties:
using Volo.Abp.Identity; using Volo.Abp.ObjectExtending; public class MyUserService : ITransientDependency { private readonly IRepository<IdentityUser, Guid> _userRepository; public MyUserService(IRepository<IdentityUser, Guid> userRepository) { _userRepository = userRepository; } public async Task SetMyCustomCodeAsync(Guid userId, string code) { var user = await _userRepository.GetAsync(userId); user.SetProperty("MyCustomCode", code); await _userRepository.UpdateAsync(user); } public async Task<string> GetMyCustomCodeAsync(Guid userId) { var user = await _userRepository.GetAsync(userId); return user.GetProperty<string>("MyCustomCode"); } }Answer to your concrete question
does it mean at the moment there is no way to add/update these ExtraProperties on the AbpUser and I have to define my own Api to add/update values for this?
No.
Once you configure module entity extensions forIdentityUser, you can add/update ExtraProperties using the existing/api/identity/usersPOST/PUT endpoints. A custom API is only needed if you want totally customized behavior, not for basic ExtraProperties support.
- Sources
- Object extensions for entities and DTOs
https://abp.io/docs/latest/framework/fundamentals/object-extensions - Extending existing module entities (e.g.,
IdentityUser)
https://abp.io/docs/latest/framework/architecture/modularity/extending/customizing-application-modules-extending-entities
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
