The Application layer exposes three use cases that represent the core business operations of the CMS. Each use case is a plain C# class registered in the DI container and injected wherever it is needed. They depend exclusively on port interfaces — never on concrete infrastructure — keeping the business logic fully decoupled from EF Core, Identity, or ASP.NET Core internals.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.
AuthenticateUser
Verifies a user’s credentials and establishes an authenticated session by writing an authentication cookie. Method signatureParameters
The email address submitted by the user on the login form. Used as the lookup
key in
IUserRepository.The plain-text password submitted by the user. It is never stored — it is
compared against the stored hash via
IPasswordHasher.Verify.Return value
How it works
Look up the user by email
Calls
IUserRepository.GetByEmailAsync(email). If no record is found,
returns AuthResult.Fail("Credenciales incorrectas.") immediately —
intentionally avoiding a distinct “user not found” message to prevent user
enumeration.Verify the password hash
Passes the stored
PasswordHash and the raw input to
IPasswordHasher.Verify. A mismatch also returns
AuthResult.Fail("Credenciales incorrectas.").Sign in via ISessionManager
On success, calls
ISessionManager.SignInAsync(user), which writes an
authentication cookie carrying the user’s ID and email as claims.Source
Application/UseCases/AuthenticateUser.cs
Error conditions
| Condition | Success | Error |
|---|---|---|
| User not found | false | "Credenciales incorrectas." |
| Password mismatch | false | "Credenciales incorrectas." |
| Valid credentials | true | null |
RegisterUser
Creates a new user account by hashing the provided password, persisting the entity, and returning the new user’s ID. Method signatureParameters
The email address for the new account. Must be unique across all users — a
duplicate triggers an early-return failure before any write occurs.
The plain-text password chosen by the new user. It is hashed by
User.Create(...) via IPasswordHasher.Hash before being stored; the raw
value is never persisted.Return value
How it works
Check for a duplicate email
Calls
IUserRepository.GetByEmailAsync(email). If a record is returned,
the use case exits early with RegisterResult.Fail("Ese email ya está registrado.").
No write takes place.Create the User entity
Calls the domain factory
User.Create(email, rawPassword, _passwordHasher).
The factory hashes the password internally via IPasswordHasher.Hash and
sets all required fields on the new User instance.Persist the new user
Calls
IUserRepository.AddAsync(user), which inserts the record and
flushes the EF Core change tracker.Source
Application/UseCases/RegisterUser.cs
Error conditions
| Condition | Success | NewId | Error |
|---|---|---|---|
| Email already registered | false | null | "Ese email ya está registrado." |
| Registration successful | true | <new id> | null |
RegisterUser does not sign in the new user automatically. After a
successful registration, the caller is responsible for redirecting the user
to the login page or explicitly invoking AuthenticateUser.LogoutUser
Terminates the current user session by revoking the authentication cookie. Method signatureParameters
This method takes no parameters. It operates exclusively through theISessionManager abstraction, which reads the current HTTP context internally.
Return value
Task — the method completes when the session has been revoked. It does not
return a result object because logout is considered an unconditional operation:
if there is no active session, SignOutAsync is a no-op.
How it works
Source
Application/UseCases/LogoutUser.cs
Because
LogoutUser has a single dependency (ISessionManager) and a
single line of logic, it is deliberately thin. All cookie-handling details
live in the infrastructure adapter CookieSessionManager, keeping this use
case easy to unit-test with a mock.DTOs
Data transfer objects used as inputs and outputs for the use cases above. All three are C#record types — immutable by default, with built-in value equality.
AuthResult
Returned byAuthenticateUser.ExecuteAsync.
Application/DTOs/AuthResult.cs
AuthResult.Ok()
Factory for a successful authentication. Produces
{ Success: true, Error: null }.AuthResult.Fail(string error)
Factory for a failed authentication. Produces
{ Success: false, Error: "<message>" }.| Field | Type | Description |
|---|---|---|
Success | bool | true when authentication succeeded. |
Error | string? | Human-readable error message, or null on success. |
RegisterResult
Returned byRegisterUser.ExecuteAsync.
Application/DTOs/RegisterResult.cs
RegisterResult.Ok(int newId)
Factory for a successful registration. Carries the new user’s database ID.
Produces
{ Success: true, NewId: <id>, Error: null }.RegisterResult.Fail(string error)
Factory for a failed registration. Produces
{ Success: false, NewId: null, Error: "<message>" }.| Field | Type | Description |
|---|---|---|
Success | bool | true when the account was created. |
NewId | int? | The new user’s primary key, or null on failure. |
Error | string? | Human-readable error message, or null on success. |
LoginRequest
A strongly-typed container for the values submitted on a login form. Not passed directly toAuthenticateUser.ExecuteAsync, but used by the Blazor component
layer to bind form fields and carry the RememberMe preference.
Application/DTOs/LoginRequest.cs
| Field | Type | Default | Description |
|---|---|---|---|
Email | string | — | The email address entered by the user. |
Password | string | — | The plain-text password entered by the user. |
RememberMe | bool | false | When true, signals the session layer to issue a persistent cookie. |