Base solution for your next web application
Open Closed

Dependency injection in an entity #1909


User avatar
0
samdev created

Hello,

I'm trying to get an IsLocked property in a DTO of the User entity. In order to compute this value, I need to access one of my seeting. Do you think I should inject the setting manager in the User Entity, or is it better to implement a IsLocked method in the User Manager ? If the second solution is better, how should I link my automap to this method, please ?

Best Regards,

SamDev


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You shouldn't inject SettingManager in your entity. You can create a custom method and use it in AutoMapper, it's possible via custom value resolvers <a class="postlink" href="https://github.com/AutoMapper/AutoMapper/wiki/Custom-value-resolvers">https://github.com/AutoMapper/AutoMappe ... -resolvers</a>.

    You need to pass an instance of your custom value resolver to Automapper's ResolveUsing.

    But I think mapping should be simple, it's better to do int in your application layer rather than putting his logic in mapping.