-
Notifications
You must be signed in to change notification settings - Fork 492
feat(db): implement options pattern for database connection strings #211
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
Changes from 2 commits
c2f18db
eeabb58
8e1f1b5
1599aa1
a37656b
a40c098
245b143
4c71c73
1e4b493
ad5ffdf
7b04d41
4112f2e
ff9722f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace EvolutionaryArchitecture.Fitnet.Contracts.Data.Database; | ||
|
|
||
| using System.ComponentModel.DataAnnotations; | ||
|
|
||
| internal sealed class ContractsPersistenceOptions | ||
| { | ||
| public const string SectionName = "ConnectionStrings"; | ||
|
|
||
| [Required] public string Contracts { get; init; } = string.Empty; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,10 @@ | ||||||||||||||||||||||||
| namespace EvolutionaryArchitecture.Fitnet.Offers.Data.Database; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| using System.ComponentModel.DataAnnotations; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| internal sealed class OffersPersistenceOptions | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| public const string SectionName = "ConnectionStrings"; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
+5
to
+8
|
||||||||||||||||||||||||
| internal sealed class OffersPersistenceOptions | |
| { | |
| public const string SectionName = "ConnectionStrings"; | |
| internal static class PersistenceOptionSectionNames | |
| { | |
| public const string ConnectionStrings = "ConnectionStrings"; | |
| } | |
| internal sealed class OffersPersistenceOptions | |
| { | |
| // Use PersistenceOptionSectionNames.ConnectionStrings where needed |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,10 @@ | ||||||||||||||||||||||||
| namespace EvolutionaryArchitecture.Fitnet.Passes.Data.Database; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| using System.ComponentModel.DataAnnotations; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| internal sealed class PassesPersistenceOptions | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| public const string SectionName = "ConnectionStrings"; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
+5
to
+8
|
||||||||||||||||||||||||
| internal sealed class PassesPersistenceOptions | |
| { | |
| public const string SectionName = "ConnectionStrings"; | |
| internal static class PersistenceOptionsConstants | |
| { | |
| public const string SectionName = "ConnectionStrings"; | |
| } | |
| internal sealed class PassesPersistenceOptions | |
| { | |
| public const string SectionName = PersistenceOptionsConstants.SectionName; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace EvolutionaryArchitecture.Fitnet.Reports.DataAccess; | ||
|
|
||
| internal static class DataAccessModule | ||
| { | ||
| internal static IServiceCollection AddDataAccess(this IServiceCollection services, IConfiguration configuration) | ||
| { | ||
| services.Configure<ReportsPersistenceOptions>(configuration.GetSection(ReportsPersistenceOptions.SectionName)); | ||
| services.AddOptionsWithValidateOnStart<ReportsPersistenceOptions>(); | ||
|
|
||
| services.AddScoped<IDatabaseConnectionFactory, DatabaseConnectionFactory>(); | ||
|
|
||
| return services; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,10 @@ | ||||||||||||||||||||||||
| namespace EvolutionaryArchitecture.Fitnet.Reports.DataAccess; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| using System.ComponentModel.DataAnnotations; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| internal sealed class ReportsPersistenceOptions | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| public const string SectionName = "ConnectionStrings"; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
+5
to
+8
|
||||||||||||||||||||||||
| internal sealed class ReportsPersistenceOptions | |
| { | |
| public const string SectionName = "ConnectionStrings"; | |
| internal static class PersistenceOptionsConstants | |
| { | |
| public const string SectionName = "ConnectionStrings"; | |
| } | |
| internal sealed class ReportsPersistenceOptions | |
| { | |
| public const string SectionName = PersistenceOptionsConstants.SectionName; |
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.
The section name "ConnectionStrings" is duplicated across all persistence options classes. Consider creating a shared constant or base class to avoid code duplication and ensure consistency.