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
5 changes: 3 additions & 2 deletions Foundatio.Mediator.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<Folder Name="/samples/ModularMonolith/">
<Project Path="samples/ModularMonolithSample/src/Orders.Module/Orders.Module.csproj" />
<Project Path="samples/ModularMonolithSample/src/WebApp/WebApp.csproj" />
<Project Path="samples\ModularMonolithSample\src\Common.Module\Common.Module.csproj" Type="Classic C#" />
<Project Path="samples\ModularMonolithSample\src\Products.Module\Products.Module.csproj" Type="Classic C#" />
<Project Path="samples\ModularMonolithSample\src\Common.Module\Common.Module.csproj" Type="C#" />
<Project Path="samples\ModularMonolithSample\src\Products.Module\Products.Module.csproj" Type="C#" />
</Folder>
<Folder Name="/Solution Items/">
<File Path=".github/copilot-instructions.md" />
<File Path="build/common.props" />
<File Path="global.json" />
<File Path="README.md" />
</Folder>
<Folder Name="/src/">
Expand Down
6 changes: 6 additions & 0 deletions samples/ConsoleSample/ConsoleSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<ProjectReference Include="..\..\src\Foundatio.Mediator\Foundatio.Mediator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1" />
<PackageReference Include="MiniValidation" Version="0.9.2" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.3" />
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions samples/ConsoleSample/Messages/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace ConsoleSample.Messages;

#region Simple
/// <summary>Ping endpoint used to test connectivity.</summary>
public record Ping(string Text);
/// <summary>Gets a personalized greeting for the specified user.</summary>
public record GetGreeting(string Name);
#endregion

// Order CRUD messages
/// <summary>Creates a new order for the specified customer.</summary>
public record CreateOrder(
[Required(ErrorMessage = "Customer ID is required")]
[StringLength(50, MinimumLength = 3, ErrorMessage = "Customer ID must be between 3 and 50 characters")]
Expand All @@ -20,8 +23,11 @@ public record CreateOrder(
[Required(ErrorMessage = "Description is required")]
[StringLength(200, MinimumLength = 5, ErrorMessage = "Description must be between 5 and 200 characters")]
string Description) : IValidatable;
/// <summary>Gets an existing order by identifier.</summary>
public record GetOrder(string OrderId);
/// <summary>Updates mutable fields on an existing order.</summary>
public record UpdateOrder(string OrderId, decimal? Amount, string? Description);
/// <summary>Deletes an existing order.</summary>
public record DeleteOrder(string OrderId);

// Event messages (for publish pattern)
Expand Down
3 changes: 1 addition & 2 deletions samples/ConsoleSample/Middleware/TransactionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public void After(CreateOrder cmd, IDbTransaction transaction, ILogger<Transacti

public void Finally(CreateOrder cmd, Result? result, IDbTransaction? transaction, ILogger<TransactionMiddleware> logger)
{
if (transaction == null)
if (transaction is not FakeTransaction tx)
return;

var tx = (FakeTransaction)transaction;
if (result?.IsSuccess == true)
return;

Expand Down
26 changes: 26 additions & 0 deletions samples/ConsoleSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
using ConsoleSample;
using Foundatio.Mediator;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Scalar.AspNetCore;

if (args.Any(a => string.Equals(a, "--web", StringComparison.OrdinalIgnoreCase)))
{
await RunMinimalApiAsync(args);
return;
}

// Create application host
var builder = Host.CreateApplicationBuilder(args);
Expand All @@ -16,3 +24,21 @@
var sampleRunner = new SampleRunner(mediator, host.Services);

await sampleRunner.RunAllSamplesAsync();

static async Task RunMinimalApiAsync(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureServices();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApi();

var app = builder.Build();
app.MapOpenApi();
app.MapScalarApiReference(options =>
{
options.Title = "Foundatio.Mediator Console Sample";
});
app.MapMediatorEndpoints();

await app.RunAsync();
}
2 changes: 1 addition & 1 deletion src/Foundatio.Mediator.Abstractions/MediatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static IServiceCollection AddMediator(this IServiceCollection services, M

if (configuration.Assemblies == null)
{
configuration.Assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && !a.FullName.StartsWith("System.")).ToList();
configuration.Assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a is { IsDynamic: false, FullName: not null } && !a.FullName.StartsWith("System.")).ToList();
}

services.Add(ServiceDescriptor.Describe(typeof(IMediator), typeof(Mediator), configuration.MediatorLifetime));
Expand Down
Loading
Loading