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.
UserRepository implements IUserRepository using EF Core 10 and a SQLite database via AppDbContext. It is registered as Scoped in DI, meaning one instance is created per HTTP request and shared across all services resolved within that same request lifetime.
Methods
GetByEmailAsync
Users DbSet for the first record whose Email column matches the supplied string. The comparison is performed by the database engine (case sensitivity depends on the SQLite collation). Returns null when no matching user is found. Internally delegates to EF Core’s FirstOrDefaultAsync, keeping the call fully asynchronous and avoiding blocking the thread pool.
AddAsync
Added state and immediately flushes it to the database by calling SaveChangesAsync(). After this method completes, user.Id will be populated with the auto-incremented value assigned by SQLite.
Full source
Infrastructure/Persistence/Repositories/UserRepository.cs
AppDbContext
AppDbContext extends EF Core’s DbContext and defines the single Users DbSet. The only explicit configuration applied is a unique index on the Email column, enforced at the schema level.
Infrastructure/Persistence/Context/AppDbContext.cs
Users property uses Set<User>() rather than an auto-property backed field, which is the recommended pattern in EF Core 8+ to avoid nullable reference warning noise while keeping the DbSet non-nullable in consuming code.
DI registration
AppDbContext is registered with the SQLite provider, and UserRepository is bound to the IUserRepository interface — both as Scoped services:
Program.cs
Default connection string is read from appsettings.json (or environment-specific overrides). For SQLite the value is typically a file path, e.g.:
appsettings.json