Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions .github/workflows/chapter-3-contracts-package-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ name: Contracts package workflow

on:
push:
branches: [ "main" ]
branches: ["main"]
paths:
- 'Chapter-3-microservice-extraction/Fitnet.Contracts/Src/Fitnet.Contracts.IntegrationEvents/**'
- "Chapter-3-microservice-extraction/Fitnet.Contracts/Src/Fitnet.Contracts.IntegrationEvents/**"
pull_request:
branches: [ "main" ]
branches: ["main"]
paths:
- 'Chapter-3-microservice-extraction/Fitnet.Contracts/Src/Fitnet.Contracts.IntegrationEvents/**'
- "Chapter-3-microservice-extraction/Fitnet.Contracts/Src/Fitnet.Contracts.IntegrationEvents/**"

env:
CHAPTER_DIR: 'Chapter-3-microservice-extraction/Fitnet.Contracts/Src'
NUGET_SOURCE_NAME: "evolutionaryArchitecture"
CHAPTER_DIR: "Chapter-3-microservice-extraction/Fitnet.Contracts/Src"
NUGET_SOURCE_NAME: "EvolutionaryArchitecture"

jobs:
build:
Expand All @@ -22,22 +22,22 @@ jobs:
runs-on: ubuntu-latest
name: Build
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Add Evolutionary Architecture Nuget Source
uses: evolutionary-architecture/evolutionary-architecture-by-example/.github@main
with:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Add Evolutionary Architecture Nuget Source
uses: evolutionary-architecture/evolutionary-architecture-by-example/.github@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
owner: ${{ github.repository_owner }}
path: ${{ env.CHAPTER_DIR }}
nuget-source-name: ${{ env.NUGET_SOURCE_NAME }}
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore

pack:
defaults:
Expand All @@ -48,19 +48,19 @@ jobs:
if: github.ref == 'refs/heads/main'
name: Pack and Publish
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Add Evolutionary Architecture Nuget Source
uses: evolutionary-architecture/evolutionary-architecture-by-example/.github@main
with:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x
- name: Add Evolutionary Architecture Nuget Source
uses: evolutionary-architecture/evolutionary-architecture-by-example/.github@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
owner: ${{ github.repository_owner }}
path: ${{ env.CHAPTER_DIR }}
nuget-source-name: ${{ env.NUGET_SOURCE_NAME }}
- name: Pack Project
run: dotnet pack Fitnet.Contracts.IntegrationEvents/Fitnet.Contracts.IntegrationEvents.csproj -c Release
- name: Publish Packages
run: dotnet nuget push "Fitnet.Contracts.IntegrationEvents/bin/Release/EvolutionaryArchitecture.Fitnet.Contracts.IntegrationEvents.*.nupkg" --source ${{ env.NUGET_SOURCE_NAME }} --api-key ${{ secrets.GITHUB_TOKEN }}
- name: Pack Project
run: dotnet pack Fitnet.Contracts.IntegrationEvents/Fitnet.Contracts.IntegrationEvents.csproj -c Release
- name: Publish Packages
run: dotnet nuget push "Fitnet.Contracts.IntegrationEvents/bin/Release/EvolutionaryArchitecture.Fitnet.Contracts.IntegrationEvents.*.nupkg" --source ${{ env.NUGET_SOURCE_NAME }} --api-key ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/chapter-3-contracts-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ on:

env:
CHAPTER_DIR: "Chapter-3-microservice-extraction/Fitnet.Contracts/Src"
NUGET_SOURCE_NAME: "evolutionaryArchitecture"
NUGET_SOURCE_NAME: "EvolutionaryArchitecture"

jobs:
build:
defaults:
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/chapter-3-package-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ name: Chapter 3 package workflow

on:
push:
branches: [ "main" ]
branches: ["main"]
paths:
- 'Chapter-3-microservice-extraction/Fitnet.Common/**'
- "Chapter-3-microservice-extraction/Fitnet.Common/**"
pull_request:
branches: [ "main" ]
branches: ["main"]
paths:
- 'Chapter-3-microservice-extraction/Fitnet.Common/**'
- "Chapter-3-microservice-extraction/Fitnet.Common/**"

env:
CHAPTER_DIR: 'Chapter-3-microservice-extraction/Fitnet.Common'
NUGET_SOURCE_NAME: "evolutionaryArchitecture"
CHAPTER_DIR: "Chapter-3-microservice-extraction/Fitnet.Common"
NUGET_SOURCE_NAME: "EvolutionaryArchitecture"

jobs:
jobs:
build:
defaults:
run:
Expand All @@ -31,7 +31,7 @@ jobs:
run: dotnet restore
- name: Build
run: dotnet build --no-restore

test:
defaults:
run:
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Test
run: dotnet test

pack:
pack:
defaults:
run:
working-directory: ${{ env.CHAPTER_DIR }}
Expand All @@ -65,7 +65,7 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.x

- name: Pack Projects
run: |
dotnet pack Fitnet.Common.Api/Fitnet.Common.Api.csproj -c Release
Expand All @@ -80,7 +80,7 @@ jobs:
owner: ${{ github.repository_owner }}
path: ${{ env.CHAPTER_DIR }}
nuget-source-name: ${{ env.NUGET_SOURCE_NAME }}

- name: Publish Packages
run: |
dotnet nuget push "Fitnet.Common.Api/bin/Release/EvolutionaryArchitecture.Fitnet.Common.Api.*.nupkg" --source ${{ env.NUGET_SOURCE_NAME }} --api-key ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/chapter-3-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

env:
CHAPTER_DIR: "Chapter-3-microservice-extraction/Fitnet/Src"
NUGET_SOURCE_NAME: "evolutionaryArchitecture"
NUGET_SOURCE_NAME: "EvolutionaryArchitecture"

jobs:
build:
Expand Down
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
@@ -1,15 +1,21 @@
namespace EvolutionaryArchitecture.Fitnet.Contracts.Data.Database;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;

internal static class DatabaseModule
{
private const string ConnectionStringName = "Contracts";

internal static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString(ConnectionStringName);
services.AddDbContext<ContractsPersistence>(options => options.UseNpgsql(connectionString));
services.Configure<ContractsPersistenceOptions>(
configuration.GetSection(ContractsPersistenceOptions.SectionName));
services.AddOptionsWithValidateOnStart<ContractsPersistenceOptions>();
services.AddDbContext<ContractsPersistence>((serviceProvider, options) =>
{
var persistenceOptions = serviceProvider.GetRequiredService<IOptions<ContractsPersistenceOptions>>();
var connectionString = persistenceOptions.Value.Contracts;
options.UseNpgsql(connectionString);
});

return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
namespace EvolutionaryArchitecture.Fitnet.Offers.Data.Database;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;

internal static class DatabaseModule
{
private const string ConnectionStringName = "Offers";

internal static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString(ConnectionStringName);
services.AddDbContext<OffersPersistence>(options => options.UseNpgsql(connectionString));
services.Configure<OffersPersistenceOptions>(configuration.GetSection(OffersPersistenceOptions.SectionName));
services.AddOptionsWithValidateOnStart<OffersPersistenceOptions>();
services.AddDbContext<OffersPersistence>((serviceProvider, options) =>
{
var persistenceOptions = serviceProvider.GetRequiredService<IOptions<OffersPersistenceOptions>>();
var connectionString = persistenceOptions.Value.Offers;
options.UseNpgsql(connectionString);
});

return services;
}
Expand All @@ -20,4 +25,4 @@ internal static IApplicationBuilder UseDatabase(this IApplicationBuilder applica

return applicationBuilder;
}
}
}
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";

[Required] public string Offers { get; init; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
namespace EvolutionaryArchitecture.Fitnet.Passes.Data.Database;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;

internal static class DatabaseModule
{
private const string ConnectionStringName = "Passes";

internal static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString(ConnectionStringName);
services.AddDbContext<PassesPersistence>(options => options.UseNpgsql(connectionString));
services.Configure<PassesPersistenceOptions>(configuration.GetSection(PassesPersistenceOptions.SectionName));
services.AddOptionsWithValidateOnStart<PassesPersistenceOptions>();
services.AddDbContext<PassesPersistence>((serviceProvider, options) =>
{
var persistenceOptions = serviceProvider.GetRequiredService<IOptions<PassesPersistenceOptions>>();
var connectionString = persistenceOptions.Value.Passes;
options.UseNpgsql(connectionString);
});

return services;
}
Expand Down
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";

[Required] public string Passes { get; init; } = string.Empty;
}
3 changes: 2 additions & 1 deletion Chapter-1-initial-architecture/Src/Fitnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
builder.Services.AddRequestsValidations();
builder.Services.AddClock();

// Add modules - each module registers its own options with validation
builder.Services.AddPasses(builder.Configuration);
builder.Services.AddContracts(builder.Configuration);
builder.Services.AddOffers(builder.Configuration);
builder.Services.AddReports();
builder.Services.AddReports(builder.Configuration);

await using var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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";

[Required] public string Reports { get; init; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace EvolutionaryArchitecture.Fitnet.Reports;

internal static class ReportsModule
{
internal static IServiceCollection AddReports(this IServiceCollection services)
internal static IServiceCollection AddReports(this IServiceCollection services, IConfiguration configuration)
{
services.AddDataAccess();
services.AddDataAccess(configuration);
services.AddNewPassesRegistrationsPerMonthReport();

return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.11.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<PackageReference Include="FluentValidation" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.32.0.97167" />
<PackageReference Include="System.Text.Encodings.Web" Version="9.0.0" />
<PackageReference Include="MediatR" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="System.Text.Encodings.Web" />
</ItemGroup>

</Project>
Loading