Open Closed

How to map RegisterDto properties to IdentityUser #2149


User avatar
0
rahul.patel@parsus.com created

Hi,

After going through ABP's extensive Extra Properties feature, I still don't see how we can use it to map some obvious properties like Name and Surname during registration without modifying module code. In provided AccountAppService.RegisterAsync the extra properties are mapped like this:

            input.MapExtraPropertiesTo(user);

So even after adding Name and Surname as extra properties to RegisterDto those properties will not get mapped to the IdentityUser object.

Only option to avoid modifying source code seems to be to override the AccountAppService by calling the base method, map add'l properties after create, and do a follow up UserManager.UpdateAsync.

        public override async Task<IdentityUserDto> RegisterAsync(RegisterDto input)
        {
            var baseResult = await base.RegisterAsync(input);

            // Handle extra properties
            var user = await UserManager.GetByIdAsync(baseResult.Id);
            user.Surname = input.GetSurname();
            user.Name = input.GetName();

            await UserManager.UpdateAsync(user);

            var result = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
            return result;
        }

It would be nice if there was a way to make MapExtraPropertiesTo extension method also map to regular properties. After checking the source, it seems that this is only possible using AutoMapper MapExtraProperties which would still require modifying module source code.

Thoughts?


4 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    This is design of Object extensions system.

    See https://support.abp.io/QA/Questions/901/How-to-extend-a-RegisterDto-entity-that-does-not-inherit-ihasextraproperties#answer-9a98960a-e8cf-b209-503c-3a003eeafdf8

    You need to override the AccountAppService

  • User Avatar
    0
    alper created
    Support Team Director

    just for an extra information https://community.abp.io/articles/how-to-add-custom-property-to-the-user-entity-6ggxiddr

  • User Avatar
    0
    rahul.patel@parsus.com created

    Hi,

    I realize we can override the AccountAppService as I mentioned in the original post. This isn't so much a support request but rather a suggestion. The ABP team has developed quite an extensive Extra Properties feature set for extensibility. It's just falling a little short in this use case. It might be useful if in AddOrUpdateProperty developers could specify whether regular properties should be mapped. Maybe it could be an additional option. This would allow developers to add extra properties to RegisterDto that could be mapped to normal properties on IdentityUser and avoid having to completely override AccountAppService.

  • User Avatar
    0
    alper created
    Support Team Director

    @rahul, thanks for your feedback. I have forwarded your request to the Framework team.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11