Skip to content

Commit

Permalink
Added correlation common package
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmatys committed Aug 13, 2024
1 parent b1aa1eb commit 8899066
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release-correlation-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: SOFTURE COMMON CORRELATION - RELEASE NEW VERSION TO NUGET.ORG

on:
release:
types: [released]

jobs:
publishing:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: ⚙️ Install dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.100

- name: 🔗 Restore dependencies
run: dotnet restore ./API

- name: 📂 Create new nuget package
run: dotnet pack --no-restore -c Release -o ./artifacts /p:PackageVersion=${{ github.ref_name }} /p:Version=${{ github.ref_name }} ./API/SOFTURE.Common.Correlation/SOFTURE.Common.Correlation.csproj
continue-on-error: false

- name: 🚀 Push new nuget package
run: dotnet nuget push ./artifacts/SOFTURE.Common.Correlation.${{ github.ref_name }}.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
6 changes: 6 additions & 0 deletions API/API.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SOFTURE.Common.HealthCheck", "SOFTURE.Common.HealthCheck\SOFTURE.Common.HealthCheck.csproj", "{5D6F7130-2C65-4BB3-A81C-5975E9CEEE9A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SOFTURE.Common.Correlation", "SOFTURE.Common.Correlation\SOFTURE.Common.Correlation.csproj", "{8D236EE2-807F-4491-ADE3-B414A39AE8D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,5 +14,9 @@ Global
{5D6F7130-2C65-4BB3-A81C-5975E9CEEE9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D6F7130-2C65-4BB3-A81C-5975E9CEEE9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D6F7130-2C65-4BB3-A81C-5975E9CEEE9A}.Release|Any CPU.Build.0 = Release|Any CPU
{8D236EE2-807F-4491-ADE3-B414A39AE8D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D236EE2-807F-4491-ADE3-B414A39AE8D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D236EE2-807F-4491-ADE3-B414A39AE8D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D236EE2-807F-4491-ADE3-B414A39AE8D8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions API/SOFTURE.Common.Correlation/Consts/CorrelationConsts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SOFTURE.Common.Correlation.Consts;

public static class CorrelationConsts
{
public const string CorrelationHeader = "X-Correlation-Id";
}
15 changes: 15 additions & 0 deletions API/SOFTURE.Common.Correlation/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using SOFTURE.Common.Correlation.Providers;

namespace SOFTURE.Common.Correlation
{
public static class DependencyInjection
{
public static IServiceCollection AddCommonCorrelationProvider(this IServiceCollection services)
{
services.AddScoped<ICorrelationProvider, CorrelationProvider>();

return services;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using SOFTURE.Common.Correlation.ValueObjects;

namespace SOFTURE.Common.Correlation.Generators;

public static class CorrelationGenerator
{
public static CorrelationId Generate() => new(Guid.NewGuid());
}
18 changes: 18 additions & 0 deletions API/SOFTURE.Common.Correlation/Providers/CorrelationProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using SOFTURE.Common.Correlation.ValueObjects;

namespace SOFTURE.Common.Correlation.Providers;

public interface ICorrelationProvider
{
CorrelationId? Get();
void Set(CorrelationId correlationId);
}

public sealed class CorrelationProvider : ICorrelationProvider
{
private CorrelationId? CorrelationId { get; set; }

public CorrelationId? Get() => CorrelationId;

public void Set(CorrelationId correlationId) => CorrelationId = correlationId;
}
46 changes: 46 additions & 0 deletions API/SOFTURE.Common.Correlation/SOFTURE.Common.Correlation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0"/>
<PackageReference Include="SOFTURE.Results" Version="0.0.9"/>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0"/>
<PackageReference Include="SOFTURE.Results" Version="0.0.9"/>
</ItemGroup>

<PropertyGroup>
<AssemblyName>SOFTURE.Common.Correlation</AssemblyName>
<AssemblyTitle>$(AssemblyName)</AssemblyTitle>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<Title>$(AssemblyName)</Title>
<Authors>SOFTURE</Authors>
<Copyright>Copyright (c) 2024 $(Authors)</Copyright>
<Description>SOFTURE - Correlation</Description>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<PackageId>$(AssemblyName)</PackageId>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://github.com/SOFTURE/API</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>See $(PackageProjectUrl)/blob/master/CHANGELOG.md for release notes.</PackageReleaseNotes>
<PackageTags>SOFTURE</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryType>Git</RepositoryType>
<RepositoryUrl>$(PackageProjectUrl)</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
<None Include="..\..\LICENSE" Pack="true" PackagePath="\"/>
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions API/SOFTURE.Common.Correlation/ValueObjects/CorrelationId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SOFTURE.Common.Correlation.ValueObjects;

public sealed record CorrelationId(Guid Value)
{
public static implicit operator CorrelationId(Guid value) => new(value);
public static implicit operator Guid(CorrelationId id) => id.Value;
public static implicit operator string(CorrelationId id) => id.Value.ToString();

public static CorrelationId Parse(string value) => new(Guid.Parse(value));
}

0 comments on commit 8899066

Please sign in to comment.