Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Andrespeerez/porfolio-blog/llms.txt
Use this file to discover all available pages before exploring further.
User is the only domain entity in the application. It lives in the Domain layer with no framework dependencies. Password hashing is delegated to IPasswordHasher via the factory method, keeping the entity clean.
Properties
Auto-increment primary key. This value is
0 until the entity is persisted — EF Core sets it after SaveChangesAsync() completes.The user’s email address. Initialized to
string.Empty by default. A unique index is enforced at the database level by AppDbContext.OnModelCreating.Stores the hashed representation of the user’s password. Declared with
private set, meaning it cannot be assigned from outside the User class. The only way to populate this property is through the User.Create factory method.Factory method: User.Create
The static factoryUser.Create is the single entry point for constructing a valid User instance. It accepts a plain-text password, delegates hashing to the provided IPasswordHasher, and returns a fully initialised entity ready to be persisted.
Signature
The user’s email address. Stored directly on the entity — no normalisation or validation is applied at the domain layer.
The plain-text password supplied by the caller. It is hashed immediately inside
Create and is never stored on the entity.The hasher abstraction used to compute
PasswordHash. In production this is satisfied by IdentityPasswordHasher, but any implementation of IPasswordHasher may be substituted (e.g., a test double).Domain/Entities/User.cs
PasswordHash has a private set accessor, meaning it can only be assigned inside the User class — enforcing that all hashing goes through User.Create. There is no public setter and no other constructor parameter for the hash, making it impossible to accidentally store a plain-text password on the entity.EF Core mapping
AppDbContext maps User to a Users table through EF Core’s convention-based mapping. There are no explicit [Table], [Column], or [Key] attributes on the entity — EF Core infers the table name from the DbSet<User> Users property name and treats Id as the primary key by convention.
The one non-default configuration applied in OnModelCreating is a unique index on the Email column:
Infrastructure/Persistence/Context/AppDbContext.cs
User records with the same email address will throw a DbUpdateException at the database level, regardless of any application-layer validation.