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)
-
0
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
-
0
just for an extra information https://community.abp.io/articles/how-to-add-custom-property-to-the-user-entity-6ggxiddr
-
0
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 inAddOrUpdateProperty
developers could specify whether regular properties should be mapped. Maybe it could be an additional option. This would allow developers to add extra properties toRegisterDto
that could be mapped to normal properties onIdentityUser
and avoid having to completely overrideAccountAppService
. -
0
@rahul, thanks for your feedback. I have forwarded your request to the Framework team.