-
Notifications
You must be signed in to change notification settings - Fork 456
feat(db): implement options pattern for database connection strings chapter 2 #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(db): implement options pattern for database connection strings chapter 2 #212
Conversation
…uraiton-chapter2 # Conflicts: # Chapter-1-initial-architecture/Src/Fitnet/Reports/DataAccess/DatabaseConnectionFactory.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the options pattern for database connection strings across multiple modules in the Fitnet application. It replaces direct configuration access with strongly-typed options classes that provide better type safety and validation.
- Introduces
PersistenceOptionsclasses for each module with required connection string properties - Updates database modules to use
IOptions<T>pattern with validation - Adds framework references to enable options validation features
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ReportsModule.cs (both chapters) | Updated to pass configuration to data access modules |
| *PersistenceOptions.cs files | New options classes defining connection string configurations |
| DatabaseModule.cs / DatabaseAccessModule.cs files | Refactored to use options pattern instead of direct configuration access |
| DatabaseConnectionFactory.cs | Updated to use options instead of IConfiguration |
| *.csproj files | Added framework references for ASP.NET Core features |
| Program.cs | Added comment explaining module registration pattern |
Comments suppressed due to low confidence (1)
Chapter-2-modules-separation/Src/Reports/Fitnet.Reports/DataAccess/DatabaseConnectionFactory.cs:24
- The DatabaseConnectionFactory is registered as a singleton but maintains mutable state (_connection) without thread synchronization. This could lead to race conditions when multiple threads access Create() simultaneously. Consider adding thread safety mechanisms or changing the registration lifetime.
internal sealed class DatabaseConnectionFactory(IOptions<ReportsPersistenceOptions> persistenceOptions) : IDatabaseConnectionFactory
{
private NpgsqlConnection? _connection;
public IDbConnection Create()
{
if (_connection is { State: ConnectionState.Open })
{
return _connection;
}
var connectionString = persistenceOptions.Value.Primary;
_connection = new NpgsqlConnection(connectionString);
_connection.Open();
return _connection;
}
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
No description provided.