Open Closed

ExtraProperties on AbpUser? #10270


User avatar
0
zokho created
  • 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)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    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

  • User Avatar
    0
    zokho created

    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?

  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution

    You do not need to create your own API just to use ExtraProperties on AbpUser (IdentityUser).

    ABP already wires ExtraProperties into the existing Identity user endpoints:

    • POST /api/identity/usersIdentityUserCreateDto
    • PUT /api/identity/users/{id}IdentityUserUpdateDto

    Both DTOs inherit from ExtensibleObject, and in IdentityUserAppService they are mapped to the entity like this:

    // Create
    input.MapExtraPropertiesTo(user);
    
    // Update
    input.MapExtraPropertiesTo(user);
    

    So the flow is:

    1. Define the extra properties on IdentityUser (required!)

      In your *.Domain.Shared project, usually in YourProjectModuleExtensionConfigurator.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 *.EntityFrameworkCore project (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.

    1. Send values via existing Identity endpoints

      Once the module entity extension is configured, you can create/update users by sending extraProperties in 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 extraProperties on the output DTO as read-only, the input DTOs still accept it and MapExtraPropertiesTo applies those values to the IdentityUser.ExtraProperties dictionary.

    1. 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 for IdentityUser, you can add/update ExtraProperties using the existing /api/identity/users POST/PUT endpoints. A custom API is only needed if you want totally customized behavior, not for basic ExtraProperties support.


    1. 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.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The create/update input inherits ExtensibleObject, and the app service already calls the input.MapExtraPropertiesTo(user);

    So you can update it with DTO's ExtraProperties.

    https://abp.io/docs/latest/framework/fundamentals/object-extensions#mapextrapropertiesto

    Thanks

Learn More, Pay Less
33% OFF
All Trainings!
Get Your Deal
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.2.0-preview. Updated on January 07, 2026, 08:03
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.