Home > Software design >  How to name password-less User Entity
How to name password-less User Entity

Time:09-15

I'm just wondering what is your's naming convention for Entities with less information. As example I have User class looking like this:

public class User : BaseEntity
{
    public string Nickname { get; set; }
    public string Password { get; set; }
    public string Email { get; set; }
    public UserRole Role { get; set; }
    public bool IsBanned { get; set; }
}

Now, for security reasons I need to create class containing only Nickname and Email. And I'm wondering if there are any widely accepted convention for naming this kind of classes.

CodePudding user response:

Okay, so I'm guessing that what you mean is Data Transfer Object (DTO) read more on it here: https://en.wikipedia.org/wiki/Data_transfer_object#:~:text=In the field of programming a data transfer,services), where each call is an expensive operation.

There is more than one convention for naming them. One option is just to call them UserDto if you will be using the same DTO for all requests connected with the User.

Another approach is CQRS (see more here: https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs or here: https://en.wikipedia.org/wiki/Command–query_separation#Command_Query_Responsibility_Separation) which separates the functionality into commands and queries and gives a template for handling DTOs. You make a folder for operations on the User called User or UserApp, inside you have folders Commands and Queries and inside Commands, you have your DTO following naming convention: [method][Object]Command.cs, for example, CreateUserCommand.cs, ofc besides that you also have a handler for it which in this case should be named CreateUserCommandHandler.cs

  • Related