Skip to content
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

mediatr package #7

Merged
merged 1 commit into from
Nov 11, 2024
Merged
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
18 changes: 18 additions & 0 deletions .github/workflows/mediatr-nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Mediatr Nuget

on:
push:
paths:
- 'mediator/dotnet/lib/**'
- '.github/workflows/mediatr-nuget.yml'
workflow_dispatch:

jobs:
publish:
name: Pack & Publish nuget
runs-on: ubuntu-latest
steps:
- uses: astorDev/versy/calver/nuget@main
with:
project: mediator/dotnet/lib/Backi.Mediatr
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
59 changes: 59 additions & 0 deletions Backi.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "timers", "timers", "{BBB56B6A-667F-43C0-8AFE-79530301D381}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet", "dotnet", "{ADCEE902-52AF-4E52-9CEA-77450049AA7C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backi.Timers", "timers\dotnet\lib\Backi.Timers.csproj", "{01EED3EB-7E8D-4770-93DD-84669ED75D1D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "playground", "playground", "{D24565DE-D3B8-42F6-AF8B-B9E4FD3B3A41}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backi.Timers.WebApiPlayground", "timers\dotnet\playground\webapi\Backi.Timers.WebApiPlayground.csproj", "{2245AA58-D144-492A-A477-5B9A24B337A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backi.Timers.Tests", "timers\dotnet\tests\Backi.Timers.Tests.csproj", "{F9FA4AC6-6E34-4D32-8C9D-573B2321BDE7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mediator", "mediator", "{27BF9028-A9AC-4B9E-9A63-5260B70734D0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnet", "dotnet", "{7F2FF828-62E7-497D-8D5C-F0F4A1540AD1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backi.Mediatr", "mediator\dotnet\lib\Backi.Mediatr.csproj", "{1AD779EA-2592-48D0-95BB-6E68FDB5276F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{01EED3EB-7E8D-4770-93DD-84669ED75D1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01EED3EB-7E8D-4770-93DD-84669ED75D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01EED3EB-7E8D-4770-93DD-84669ED75D1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01EED3EB-7E8D-4770-93DD-84669ED75D1D}.Release|Any CPU.Build.0 = Release|Any CPU
{2245AA58-D144-492A-A477-5B9A24B337A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2245AA58-D144-492A-A477-5B9A24B337A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2245AA58-D144-492A-A477-5B9A24B337A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2245AA58-D144-492A-A477-5B9A24B337A0}.Release|Any CPU.Build.0 = Release|Any CPU
{F9FA4AC6-6E34-4D32-8C9D-573B2321BDE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9FA4AC6-6E34-4D32-8C9D-573B2321BDE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9FA4AC6-6E34-4D32-8C9D-573B2321BDE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9FA4AC6-6E34-4D32-8C9D-573B2321BDE7}.Release|Any CPU.Build.0 = Release|Any CPU
{1AD779EA-2592-48D0-95BB-6E68FDB5276F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AD779EA-2592-48D0-95BB-6E68FDB5276F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AD779EA-2592-48D0-95BB-6E68FDB5276F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AD779EA-2592-48D0-95BB-6E68FDB5276F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{ADCEE902-52AF-4E52-9CEA-77450049AA7C} = {BBB56B6A-667F-43C0-8AFE-79530301D381}
{01EED3EB-7E8D-4770-93DD-84669ED75D1D} = {ADCEE902-52AF-4E52-9CEA-77450049AA7C}
{D24565DE-D3B8-42F6-AF8B-B9E4FD3B3A41} = {ADCEE902-52AF-4E52-9CEA-77450049AA7C}
{2245AA58-D144-492A-A477-5B9A24B337A0} = {D24565DE-D3B8-42F6-AF8B-B9E4FD3B3A41}
{F9FA4AC6-6E34-4D32-8C9D-573B2321BDE7} = {ADCEE902-52AF-4E52-9CEA-77450049AA7C}
{7F2FF828-62E7-497D-8D5C-F0F4A1540AD1} = {27BF9028-A9AC-4B9E-9A63-5260B70734D0}
{1AD779EA-2592-48D0-95BB-6E68FDB5276F} = {7F2FF828-62E7-497D-8D5C-F0F4A1540AD1}
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions mediator/dotnet/lib/Backi.Mediatr.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mediatr" Version="12.4.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions mediator/dotnet/lib/ServiceScopeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Backi;

public static class ServiceScopeExtensions
{
public static async Task SendMediatorRequest<TRequest>(this IServiceScopeFactory serviceScopeFactory, ILogger? logger = null, CancellationToken? cancellationToken = null)
where TRequest : IRequest
{
logger?.LogDebug("Sending {requestType} to mediator in a new scope", typeof(TRequest));
using var scope = serviceScopeFactory.CreateScope();
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
var request = (TRequest)Activator.CreateInstance(typeof(TRequest))!;
await mediator.Send(request, cancellationToken ?? CancellationToken.None);
logger?.LogInformation("{requestType} processed by mediator", typeof(TRequest));
}
}