diff --git a/.csharpierrc.json b/.csharpierrc.json
new file mode 100644
index 0000000..6a457af
--- /dev/null
+++ b/.csharpierrc.json
@@ -0,0 +1,3 @@
+{
+ "printWidth": 120
+}
diff --git a/Build.csproj b/Build.csproj
index f62b34d..826c787 100644
--- a/Build.csproj
+++ b/Build.csproj
@@ -1,11 +1,6 @@
-
-
-
-
-
-
-
+
+
diff --git a/Directory.Build.props b/Directory.Build.props
index 157dc52..2105571 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -22,4 +22,11 @@
6.0.0
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
diff --git a/Mediator.sln b/Mediator.sln
index bc99b72..6333a66 100644
--- a/Mediator.sln
+++ b/Mediator.sln
@@ -57,6 +57,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_files", "_files", "{FDAEEF
NuGet.config = NuGet.config
README.md = README.md
version.json = version.json
+ .csharpierrc.json = .csharpierrc.json
+ Build.csproj = Build.csproj
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mediator.Tests.TransientLifetime", "test\Mediator.Tests.TransientLifetime\Mediator.Tests.TransientLifetime.csproj", "{4C18FD08-BCE4-4C6A-9D84-9A81C4561586}"
diff --git a/benchmarks/Mediator.Benchmarks/Notification/NotificationBenchmarks.cs b/benchmarks/Mediator.Benchmarks/Notification/NotificationBenchmarks.cs
index 8213bd5..88a181b 100644
--- a/benchmarks/Mediator.Benchmarks/Notification/NotificationBenchmarks.cs
+++ b/benchmarks/Mediator.Benchmarks/Notification/NotificationBenchmarks.cs
@@ -8,19 +8,19 @@ namespace Mediator.Benchmarks.Notification;
public sealed record SomeNotification(Guid Id) : INotification, MediatR.INotification;
-public sealed class SomeHandlerClass :
- INotificationHandler,
- MediatR.INotificationHandler,
- IAsyncMessageHandler
+public sealed class SomeHandlerClass
+ : INotificationHandler,
+ MediatR.INotificationHandler,
+ IAsyncMessageHandler
{
- public ValueTask Handle(SomeNotification notification, CancellationToken cancellationToken) =>
- default;
+ public ValueTask Handle(SomeNotification notification, CancellationToken cancellationToken) => default;
- public ValueTask HandleAsync(SomeNotification message, CancellationToken cancellationToken) =>
- default;
+ public ValueTask HandleAsync(SomeNotification message, CancellationToken cancellationToken) => default;
- Task MediatR.INotificationHandler.Handle(SomeNotification notification, CancellationToken cancellationToken) =>
- Task.CompletedTask;
+ Task MediatR.INotificationHandler.Handle(
+ SomeNotification notification,
+ CancellationToken cancellationToken
+ ) => Task.CompletedTask;
}
[MemoryDiagnoser]
@@ -50,26 +50,31 @@ public void Setup()
{
var services = new ServiceCollection();
services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime);
- services.AddMediatR(opts =>
- {
- _ = ServiceLifetime switch
+ services.AddMediatR(
+ opts =>
{
- ServiceLifetime.Singleton => opts.AsSingleton(),
- ServiceLifetime.Scoped => opts.AsScoped(),
- ServiceLifetime.Transient => opts.AsTransient(),
- _ => throw new InvalidOperationException(),
- };
- }, typeof(SomeHandlerClass).Assembly);
- services.AddMessagePipe(opts =>
- {
- opts.InstanceLifetime = ServiceLifetime switch
+ _ = ServiceLifetime switch
+ {
+ ServiceLifetime.Singleton => opts.AsSingleton(),
+ ServiceLifetime.Scoped => opts.AsScoped(),
+ ServiceLifetime.Transient => opts.AsTransient(),
+ _ => throw new InvalidOperationException(),
+ };
+ },
+ typeof(SomeHandlerClass).Assembly
+ );
+ services.AddMessagePipe(
+ opts =>
{
- ServiceLifetime.Singleton => InstanceLifetime.Singleton,
- ServiceLifetime.Scoped => InstanceLifetime.Scoped,
- ServiceLifetime.Transient => InstanceLifetime.Transient,
- _ => throw new InvalidOperationException(),
- };
- });
+ opts.InstanceLifetime = ServiceLifetime switch
+ {
+ ServiceLifetime.Singleton => InstanceLifetime.Singleton,
+ ServiceLifetime.Scoped => InstanceLifetime.Scoped,
+ ServiceLifetime.Transient => InstanceLifetime.Transient,
+ _ => throw new InvalidOperationException(),
+ };
+ }
+ );
_serviceProvider = services.BuildServiceProvider();
if (ServiceLifetime == ServiceLifetime.Scoped)
diff --git a/benchmarks/Mediator.Benchmarks/Request/RequestBenchmarks.cs b/benchmarks/Mediator.Benchmarks/Request/RequestBenchmarks.cs
index 1ff3132..b21ca77 100644
--- a/benchmarks/Mediator.Benchmarks/Request/RequestBenchmarks.cs
+++ b/benchmarks/Mediator.Benchmarks/Request/RequestBenchmarks.cs
@@ -10,10 +10,10 @@ public sealed record SomeRequest(Guid Id) : IRequest, MediatR.IReq
public sealed record SomeResponse(Guid Id);
-public sealed class SomeHandlerClass :
- IRequestHandler,
- MediatR.IRequestHandler,
- IAsyncRequestHandler
+public sealed class SomeHandlerClass
+ : IRequestHandler,
+ MediatR.IRequestHandler,
+ IAsyncRequestHandler
{
private static readonly SomeResponse _response = new SomeResponse(Guid.NewGuid());
@@ -22,7 +22,10 @@ public sealed class SomeHandlerClass :
public ValueTask Handle(SomeRequest request, CancellationToken cancellationToken) => _vtResponse;
- Task MediatR.IRequestHandler.Handle(SomeRequest request, CancellationToken cancellationToken) => _tResponse;
+ Task MediatR.IRequestHandler.Handle(
+ SomeRequest request,
+ CancellationToken cancellationToken
+ ) => _tResponse;
public ValueTask InvokeAsync(SomeRequest request, CancellationToken cancellationToken) => _vtResponse;
}
@@ -52,26 +55,31 @@ public void Setup()
{
var services = new ServiceCollection();
services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime);
- services.AddMediatR(opts =>
- {
- _ = ServiceLifetime switch
+ services.AddMediatR(
+ opts =>
{
- ServiceLifetime.Singleton => opts.AsSingleton(),
- ServiceLifetime.Scoped => opts.AsScoped(),
- ServiceLifetime.Transient => opts.AsTransient(),
- _ => throw new InvalidOperationException(),
- };
- }, typeof(SomeHandlerClass).Assembly);
- services.AddMessagePipe(opts =>
- {
- opts.InstanceLifetime = ServiceLifetime switch
+ _ = ServiceLifetime switch
+ {
+ ServiceLifetime.Singleton => opts.AsSingleton(),
+ ServiceLifetime.Scoped => opts.AsScoped(),
+ ServiceLifetime.Transient => opts.AsTransient(),
+ _ => throw new InvalidOperationException(),
+ };
+ },
+ typeof(SomeHandlerClass).Assembly
+ );
+ services.AddMessagePipe(
+ opts =>
{
- ServiceLifetime.Singleton => InstanceLifetime.Singleton,
- ServiceLifetime.Scoped => InstanceLifetime.Scoped,
- ServiceLifetime.Transient => InstanceLifetime.Transient,
- _ => throw new InvalidOperationException(),
- };
- });
+ opts.InstanceLifetime = ServiceLifetime switch
+ {
+ ServiceLifetime.Singleton => InstanceLifetime.Singleton,
+ ServiceLifetime.Scoped => InstanceLifetime.Scoped,
+ ServiceLifetime.Transient => InstanceLifetime.Transient,
+ _ => throw new InvalidOperationException(),
+ };
+ }
+ );
_serviceProvider = services.BuildServiceProvider();
if (ServiceLifetime == ServiceLifetime.Scoped)
diff --git a/benchmarks/Mediator.Benchmarks/Request/StreamingBenchmarks.cs b/benchmarks/Mediator.Benchmarks/Request/StreamingBenchmarks.cs
index 35dff1a..952de0d 100644
--- a/benchmarks/Mediator.Benchmarks/Request/StreamingBenchmarks.cs
+++ b/benchmarks/Mediator.Benchmarks/Request/StreamingBenchmarks.cs
@@ -7,9 +7,9 @@ namespace Mediator.Benchmarks.Request;
public sealed record SomeStreamRequest(Guid Id) : IStreamRequest, MediatR.IStreamRequest;
-public sealed class SomeStreamHandlerClass :
- IStreamRequestHandler,
- MediatR.IStreamRequestHandler
+public sealed class SomeStreamHandlerClass
+ : IStreamRequestHandler,
+ MediatR.IStreamRequestHandler
{
private static readonly SomeResponse _response = new SomeResponse(Guid.NewGuid());
@@ -26,8 +26,10 @@ async IAsyncEnumerable _enumerate()
public IAsyncEnumerable Handle(SomeStreamRequest request, CancellationToken cancellationToken) =>
_enumerate();
- IAsyncEnumerable MediatR.IStreamRequestHandler.Handle(SomeStreamRequest request, CancellationToken cancellationToken) =>
- _enumerate();
+ IAsyncEnumerable MediatR.IStreamRequestHandler.Handle(
+ SomeStreamRequest request,
+ CancellationToken cancellationToken
+ ) => _enumerate();
}
[MemoryDiagnoser]
@@ -54,16 +56,19 @@ public void Setup()
{
var services = new ServiceCollection();
services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime);
- services.AddMediatR(opts =>
- {
- _ = ServiceLifetime switch
+ services.AddMediatR(
+ opts =>
{
- ServiceLifetime.Singleton => opts.AsSingleton(),
- ServiceLifetime.Scoped => opts.AsScoped(),
- ServiceLifetime.Transient => opts.AsTransient(),
- _ => throw new InvalidOperationException(),
- };
- }, typeof(SomeHandlerClass).Assembly);
+ _ = ServiceLifetime switch
+ {
+ ServiceLifetime.Singleton => opts.AsSingleton(),
+ ServiceLifetime.Scoped => opts.AsScoped(),
+ ServiceLifetime.Transient => opts.AsTransient(),
+ _ => throw new InvalidOperationException(),
+ };
+ },
+ typeof(SomeHandlerClass).Assembly
+ );
_serviceProvider = services.BuildServiceProvider();
if (ServiceLifetime == ServiceLifetime.Scoped)
diff --git a/benchmarks/Mediator.Benchmarks/Request/StructRequestBenchmarks.cs b/benchmarks/Mediator.Benchmarks/Request/StructRequestBenchmarks.cs
index 273a35c..38c3c94 100644
--- a/benchmarks/Mediator.Benchmarks/Request/StructRequestBenchmarks.cs
+++ b/benchmarks/Mediator.Benchmarks/Request/StructRequestBenchmarks.cs
@@ -24,18 +24,26 @@ public SomeStructRequest(Guid id)
}
}
-public sealed class SomeStructHandler : IRequestHandler, MediatR.IRequestHandler, IAsyncRequestHandler
+public sealed class SomeStructHandler
+ : IRequestHandler,
+ MediatR.IRequestHandler,
+ IAsyncRequestHandler
{
private static readonly SomeResponse _response = new SomeResponse(Guid.NewGuid());
private static readonly Task _tResponse = Task.FromResult(_response);
private static ValueTask _vtResponse => new ValueTask(_response);
- public ValueTask Handle(SomeStructRequest request, CancellationToken cancellationToken) => _vtResponse;
+ public ValueTask Handle(SomeStructRequest request, CancellationToken cancellationToken) =>
+ _vtResponse;
- Task MediatR.IRequestHandler.Handle(SomeStructRequest request, CancellationToken cancellationToken) => _tResponse;
+ Task MediatR.IRequestHandler.Handle(
+ SomeStructRequest request,
+ CancellationToken cancellationToken
+ ) => _tResponse;
- public ValueTask InvokeAsync(SomeStructRequest request, CancellationToken cancellationToken) => _vtResponse;
+ public ValueTask InvokeAsync(SomeStructRequest request, CancellationToken cancellationToken) =>
+ _vtResponse;
}
[MemoryDiagnoser]
@@ -63,26 +71,31 @@ public void Setup()
{
var services = new ServiceCollection();
services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime);
- services.AddMediatR(opts =>
- {
- _ = ServiceLifetime switch
+ services.AddMediatR(
+ opts =>
{
- ServiceLifetime.Singleton => opts.AsSingleton(),
- ServiceLifetime.Scoped => opts.AsScoped(),
- ServiceLifetime.Transient => opts.AsTransient(),
- _ => throw new InvalidOperationException(),
- };
- }, typeof(SomeHandlerClass).Assembly);
- services.AddMessagePipe(opts =>
- {
- opts.InstanceLifetime = ServiceLifetime switch
+ _ = ServiceLifetime switch
+ {
+ ServiceLifetime.Singleton => opts.AsSingleton(),
+ ServiceLifetime.Scoped => opts.AsScoped(),
+ ServiceLifetime.Transient => opts.AsTransient(),
+ _ => throw new InvalidOperationException(),
+ };
+ },
+ typeof(SomeHandlerClass).Assembly
+ );
+ services.AddMessagePipe(
+ opts =>
{
- ServiceLifetime.Singleton => InstanceLifetime.Singleton,
- ServiceLifetime.Scoped => InstanceLifetime.Scoped,
- ServiceLifetime.Transient => InstanceLifetime.Transient,
- _ => throw new InvalidOperationException(),
- };
- });
+ opts.InstanceLifetime = ServiceLifetime switch
+ {
+ ServiceLifetime.Singleton => InstanceLifetime.Singleton,
+ ServiceLifetime.Scoped => InstanceLifetime.Scoped,
+ ServiceLifetime.Transient => InstanceLifetime.Transient,
+ _ => throw new InvalidOperationException(),
+ };
+ }
+ );
_serviceProvider = services.BuildServiceProvider();
if (ServiceLifetime == ServiceLifetime.Scoped)
@@ -96,7 +109,9 @@ public void Setup()
_mediator = _serviceProvider.GetRequiredService();
_concreteMediator = _serviceProvider.GetRequiredService();
_mediatr = _serviceProvider.GetRequiredService();
- _messagePipeHandler = _serviceProvider.GetRequiredService>();
+ _messagePipeHandler = _serviceProvider.GetRequiredService<
+ IAsyncRequestHandler
+ >();
_handler = _serviceProvider.GetRequiredService();
_request = new(Guid.NewGuid());
}
diff --git a/samples/ASPNET/Controllers/WeatherForecastController.cs b/samples/ASPNET/Controllers/WeatherForecastController.cs
index d7b5961..759aa98 100644
--- a/samples/ASPNET/Controllers/WeatherForecastController.cs
+++ b/samples/ASPNET/Controllers/WeatherForecastController.cs
@@ -8,7 +8,6 @@ namespace ASPNET.Controllers
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
-
private readonly ILogger _logger;
private readonly IMediator _mediator;
diff --git a/samples/ASPNET/Program.cs b/samples/ASPNET/Program.cs
index f017f47..97c6b37 100644
--- a/samples/ASPNET/Program.cs
+++ b/samples/ASPNET/Program.cs
@@ -3,6 +3,7 @@
// Add services to the container.
builder.Services.AddControllers();
+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
diff --git a/samples/ASPNET/WeatherForecasts/GetWeatherForecasts.cs b/samples/ASPNET/WeatherForecasts/GetWeatherForecasts.cs
index 3edfa89..2cb61ed 100644
--- a/samples/ASPNET/WeatherForecasts/GetWeatherForecasts.cs
+++ b/samples/ASPNET/WeatherForecasts/GetWeatherForecasts.cs
@@ -8,18 +8,35 @@ public sealed record GetWeatherForecastsHandler : IQueryHandler> Handle(GetWeatherForecasts query, CancellationToken cancellationToken)
+ public ValueTask> Handle(
+ GetWeatherForecasts query,
+ CancellationToken cancellationToken
+ )
{
- var result = Enumerable.Range(1, 5).Select(index => new WeatherForecast
- {
- Date = DateTime.Now.AddDays(index),
- TemperatureC = Random.Shared.Next(-20, 55),
- Summary = Summaries[Random.Shared.Next(Summaries.Length)]
- })
- .ToArray();
+ var result = Enumerable
+ .Range(1, 5)
+ .Select(
+ index =>
+ new WeatherForecast
+ {
+ Date = DateTime.Now.AddDays(index),
+ TemperatureC = Random.Shared.Next(-20, 55),
+ Summary = Summaries[Random.Shared.Next(Summaries.Length)]
+ }
+ )
+ .ToArray();
return new ValueTask>(result);
}
diff --git a/samples/ASPNET/WeatherForecasts/WeatherForecast.cs b/samples/ASPNET/WeatherForecasts/WeatherForecast.cs
index a153aa0..4448b82 100644
--- a/samples/ASPNET/WeatherForecasts/WeatherForecast.cs
+++ b/samples/ASPNET/WeatherForecasts/WeatherForecast.cs
@@ -10,4 +10,4 @@ public class WeatherForecast
public string? Summary { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/samples/ASPNET_CleanArchitecture/AspNetSample.Api/Program.cs b/samples/ASPNET_CleanArchitecture/AspNetSample.Api/Program.cs
index 740c214..6ccdb57 100644
--- a/samples/ASPNET_CleanArchitecture/AspNetSample.Api/Program.cs
+++ b/samples/ASPNET_CleanArchitecture/AspNetSample.Api/Program.cs
@@ -9,13 +9,19 @@ public static void Main(string[] args)
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
- .ConfigureWebHostDefaults(webBuilder =>
- {
- webBuilder.UseStartup();
- })
- .ConfigureLogging(builder =>
- builder.AddSimpleConsole(Options =>
+ .ConfigureWebHostDefaults(
+ webBuilder =>
{
- Options.SingleLine = true;
- }));
+ webBuilder.UseStartup();
+ }
+ )
+ .ConfigureLogging(
+ builder =>
+ builder.AddSimpleConsole(
+ Options =>
+ {
+ Options.SingleLine = true;
+ }
+ )
+ );
}
diff --git a/samples/ASPNET_CleanArchitecture/AspNetSample.Api/Startup.cs b/samples/ASPNET_CleanArchitecture/AspNetSample.Api/Startup.cs
index c0f9d77..0b17dcb 100644
--- a/samples/ASPNET_CleanArchitecture/AspNetSample.Api/Startup.cs
+++ b/samples/ASPNET_CleanArchitecture/AspNetSample.Api/Startup.cs
@@ -23,10 +23,12 @@ public void ConfigureServices(IServiceCollection services)
services.AddApplication();
services.AddInfrastructure();
- services.AddSwaggerGen(c =>
- {
- c.SwaggerDoc("v1", new OpenApiInfo { Title = "AspNetSample.Api", Version = "v1" });
- });
+ services.AddSwaggerGen(
+ c =>
+ {
+ c.SwaggerDoc("v1", new OpenApiInfo { Title = "AspNetSample.Api", Version = "v1" });
+ }
+ );
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -43,9 +45,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseAuthorization();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllers();
- });
+ app.UseEndpoints(
+ endpoints =>
+ {
+ endpoints.MapControllers();
+ }
+ );
}
}
diff --git a/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Pipeline/ErrorLoggingBehaviour.cs b/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Pipeline/ErrorLoggingBehaviour.cs
index 0d1578b..515029a 100644
--- a/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Pipeline/ErrorLoggingBehaviour.cs
+++ b/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Pipeline/ErrorLoggingBehaviour.cs
@@ -4,7 +4,7 @@
namespace AspNetSample.Application;
public sealed class ErrorLoggingBehaviour : IPipelineBehavior
- where TMessage : IMessage
+ where TMessage : IMessage
{
private readonly ILogger> _logger;
@@ -13,7 +13,11 @@ public ErrorLoggingBehaviour(ILogger>
_logger = logger;
}
- public async ValueTask Handle(TMessage message, CancellationToken cancellationToken, MessageHandlerDelegate next)
+ public async ValueTask Handle(
+ TMessage message,
+ CancellationToken cancellationToken,
+ MessageHandlerDelegate next
+ )
{
try
{
diff --git a/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Pipeline/MessageValidatorBehaviour.cs b/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Pipeline/MessageValidatorBehaviour.cs
index e44682b..f36290d 100644
--- a/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Pipeline/MessageValidatorBehaviour.cs
+++ b/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Pipeline/MessageValidatorBehaviour.cs
@@ -3,9 +3,13 @@
namespace AspNetSample.Application;
public sealed class MessageValidatorBehaviour : IPipelineBehavior
- where TMessage : IValidate
+ where TMessage : IValidate
{
- public ValueTask Handle(TMessage message, CancellationToken cancellationToken, MessageHandlerDelegate next)
+ public ValueTask Handle(
+ TMessage message,
+ CancellationToken cancellationToken,
+ MessageHandlerDelegate next
+ )
{
if (!message.IsValid(out var validationError))
throw new ValidationException(validationError);
diff --git a/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Todos/TodoItemQueryHandler.cs b/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Todos/TodoItemQueryHandler.cs
index 07804df..6012d22 100644
--- a/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Todos/TodoItemQueryHandler.cs
+++ b/samples/ASPNET_CleanArchitecture/AspNetSample.Application/Todos/TodoItemQueryHandler.cs
@@ -15,8 +15,6 @@ public async ValueTask> Handle(GetTodoItems query, Canc
{
var items = await _repository.GetItems(cancellationToken);
- return items
- .Select(i => new TodoItemDto(i.Title, i.Text, i.Done))
- .ToArray();
+ return items.Select(i => new TodoItemDto(i.Title, i.Text, i.Done)).ToArray();
}
}
diff --git a/samples/ASPNET_CleanArchitecture/AspNetSample.Application/ValidationException.cs b/samples/ASPNET_CleanArchitecture/AspNetSample.Application/ValidationException.cs
index 6417429..c5c55c4 100644
--- a/samples/ASPNET_CleanArchitecture/AspNetSample.Application/ValidationException.cs
+++ b/samples/ASPNET_CleanArchitecture/AspNetSample.Application/ValidationException.cs
@@ -2,7 +2,8 @@ namespace AspNetSample.Application;
public sealed class ValidationException : Exception
{
- public ValidationException(ValidationError validationError) : base("Validation error") => ValidationError = validationError;
+ public ValidationException(ValidationError validationError) : base("Validation error") =>
+ ValidationError = validationError;
public ValidationError ValidationError { get; }
}
diff --git a/samples/SimpleConsole/Program.cs b/samples/SimpleConsole/Program.cs
index 9043d66..494ae0d 100644
--- a/samples/SimpleConsole/Program.cs
+++ b/samples/SimpleConsole/Program.cs
@@ -8,16 +8,18 @@
// This extensions method is generated, and is put in the "Microsoft.Extensions.DependencyInjection" namespace.
// We override the namespace in the "MediatorOptions" attribute above.
-services.AddMediator(options =>
-{
- options.Namespace = null;
- options.ServiceLifetime = ServiceLifetime.Transient;
-});
+services.AddMediator(
+ options =>
+ {
+ options.Namespace = null;
+ options.ServiceLifetime = ServiceLifetime.Transient;
+ }
+);
// Standard handlers are added by default, but we need to add pipeline steps manually.
// Here are two examples.
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(GenericLoggerHandler<,>)); // This will run 1st
-services.AddSingleton, PingValidator>(); // This will run 2nd
+services.AddSingleton, PingValidator>(); // This will run 2nd
var serviceProvider = services.BuildServiceProvider();
@@ -46,7 +48,11 @@ public sealed record Pong(Guid Id);
public sealed class GenericLoggerHandler : IPipelineBehavior
where TMessage : IMessage
{
- public async ValueTask Handle(TMessage message, CancellationToken cancellationToken, MessageHandlerDelegate next)
+ public async ValueTask Handle(
+ TMessage message,
+ CancellationToken cancellationToken,
+ MessageHandlerDelegate next
+ )
{
Console.WriteLine("1) Running logger handler");
try
@@ -65,7 +71,11 @@ public async ValueTask Handle(TMessage message, CancellationToken can
public sealed class PingValidator : IPipelineBehavior
{
- public ValueTask Handle(Ping request, CancellationToken cancellationToken, MessageHandlerDelegate next)
+ public ValueTask Handle(
+ Ping request,
+ CancellationToken cancellationToken,
+ MessageHandlerDelegate next
+ )
{
Console.WriteLine("2) Running ping validator");
if (request is null || request.Id == default)
diff --git a/samples/SimpleConsoleAOT/Program.cs b/samples/SimpleConsoleAOT/Program.cs
index 4fb07d9..36252c9 100644
--- a/samples/SimpleConsoleAOT/Program.cs
+++ b/samples/SimpleConsoleAOT/Program.cs
@@ -12,7 +12,7 @@
// Standard handlers are added by default, but we need to add pipeline steps manually.
// Here are two examples.
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(GenericLoggerHandler<,>)); // This will run 1st
-services.AddSingleton, PingValidator>(); // This will run 2nd
+services.AddSingleton, PingValidator>(); // This will run 2nd
var serviceProvider = services.BuildServiceProvider();
@@ -41,7 +41,11 @@ public sealed record Pong(Guid Id);
public sealed class GenericLoggerHandler : IPipelineBehavior
where TMessage : IMessage
{
- public async ValueTask Handle(TMessage message, CancellationToken cancellationToken, MessageHandlerDelegate next)
+ public async ValueTask Handle(
+ TMessage message,
+ CancellationToken cancellationToken,
+ MessageHandlerDelegate next
+ )
{
Console.WriteLine("1) Running logger handler");
try
@@ -60,7 +64,11 @@ public async ValueTask Handle(TMessage message, CancellationToken can
public sealed class PingValidator : IPipelineBehavior
{
- public ValueTask Handle(Ping request, CancellationToken cancellationToken, MessageHandlerDelegate next)
+ public ValueTask Handle(
+ Ping request,
+ CancellationToken cancellationToken,
+ MessageHandlerDelegate next
+ )
{
Console.WriteLine("2) Running ping validator");
if (request is null || request.Id == default)
diff --git a/samples/SimpleEndToEnd/Program.cs b/samples/SimpleEndToEnd/Program.cs
index ecdc750..8ca0605 100644
--- a/samples/SimpleEndToEnd/Program.cs
+++ b/samples/SimpleEndToEnd/Program.cs
@@ -8,6 +8,7 @@
var services = new ServiceCollection();
services.AddMediator();
+
// Ordering of pipeline behavior registrations matter!
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(ErrorLoggerHandler<,>));
services.AddSingleton, PingValidator>();
@@ -32,13 +33,13 @@
var statsHandler = sp.GetRequiredService();
var (messageCount, messageErrorCount) = statsHandler.Stats;
+
// First Ping succeeded, second failed validation
-Debug.Assert(messageCount == 2, "We sent 2 pings");
+Debug.Assert(messageCount == 2, "We sent 2 pings");
Debug.Assert(messageErrorCount == 1, "1 of them failed validation");
Console.WriteLine("Done!");
-
// Types used below
public sealed record Ping(Guid Id) : IRequest;
@@ -55,7 +56,11 @@ public ValueTask Handle(Ping request, CancellationToken cancellationToken)
public sealed class PingValidator : IPipelineBehavior
{
- public ValueTask Handle(Ping request, CancellationToken cancellationToken, MessageHandlerDelegate next)
+ public ValueTask Handle(
+ Ping request,
+ CancellationToken cancellationToken,
+ MessageHandlerDelegate next
+ )
{
if (request is null || request.Id == default)
throw new ArgumentException("Invalid input");
@@ -78,7 +83,11 @@ public ErrorLoggerHandler(IMediator mediator)
_mediator = mediator;
}
- public async ValueTask Handle(TMessage message, CancellationToken cancellationToken, MessageHandlerDelegate next)
+ public async ValueTask Handle(
+ TMessage message,
+ CancellationToken cancellationToken,
+ MessageHandlerDelegate next
+ )
{
try
{
diff --git a/samples/SimpleStreaming/Program.cs b/samples/SimpleStreaming/Program.cs
index d6b1966..7ef1e03 100644
--- a/samples/SimpleStreaming/Program.cs
+++ b/samples/SimpleStreaming/Program.cs
@@ -38,7 +38,10 @@ public sealed record Pong(Guid Id);
public sealed class PingHandler : IStreamRequestHandler
{
- public async IAsyncEnumerable Handle(StreamPing request, [EnumeratorCancellation] CancellationToken cancellationToken)
+ public async IAsyncEnumerable Handle(
+ StreamPing request,
+ [EnumeratorCancellation] CancellationToken cancellationToken
+ )
{
for (int i = 0; i < 5; i++)
{
diff --git a/samples/WPFApp/MainWindow.xaml.cs b/samples/WPFApp/MainWindow.xaml.cs
index 821bbb4..78d8f5e 100644
--- a/samples/WPFApp/MainWindow.xaml.cs
+++ b/samples/WPFApp/MainWindow.xaml.cs
@@ -36,22 +36,30 @@ public MainWindow()
lvDataBinding.ItemsSource = _items;
- _ = Task.Run(async () =>
- {
- var sp = App.ServiceProvider;
+ _ = Task.Run(
+ async () =>
+ {
+ var sp = App.ServiceProvider;
- var mediator = sp.GetRequiredService();
+ var mediator = sp.GetRequiredService();
- for (int i = 0; i < 100; i++)
- {
- var ping = new Ping();
- var pong = await mediator.Send(ping);
-
- lvDataBinding.Dispatcher.Invoke(() => { _items.Enqueue((ping, pong)); }, DispatcherPriority.Render);
-
- await Task.Delay(2000);
+ for (int i = 0; i < 100; i++)
+ {
+ var ping = new Ping();
+ var pong = await mediator.Send(ping);
+
+ lvDataBinding.Dispatcher.Invoke(
+ () =>
+ {
+ _items.Enqueue((ping, pong));
+ },
+ DispatcherPriority.Render
+ );
+
+ await Task.Delay(2000);
+ }
}
- });
+ );
}
}
diff --git a/samples/WPFApp/Properties/AssemblyInfo.cs b/samples/WPFApp/Properties/AssemblyInfo.cs
index fe8d238..0fc0498 100644
--- a/samples/WPFApp/Properties/AssemblyInfo.cs
+++ b/samples/WPFApp/Properties/AssemblyInfo.cs
@@ -1,4 +1,4 @@
-using System.Reflection;
+using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -33,9 +33,9 @@
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
- //(used if a resource is not found in the page,
- // or application resource dictionaries)
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
- //(used if a resource is not found in the page,
- // app, or any theme specific resource dictionaries)
+//(used if a resource is not found in the page,
+// app, or any theme specific resource dictionaries)
)]
diff --git a/src/Mediator.SourceGenerator.Implementation/Analysis/CompilationAnalyzer.cs b/src/Mediator.SourceGenerator.Implementation/Analysis/CompilationAnalyzer.cs
index 2c98dfe..c51b1a9 100644
--- a/src/Mediator.SourceGenerator.Implementation/Analysis/CompilationAnalyzer.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Analysis/CompilationAnalyzer.cs
@@ -32,14 +32,11 @@ internal sealed class CompilationAnalyzer
private readonly INamedTypeSymbol _notificationHandlerInterfaceSymbol;
private readonly INamedTypeSymbol _notificationInterfaceSymbol;
- public IEnumerable RequestMessages =>
- _requestMessages.Where(r => r.Handler is not null);
+ public IEnumerable RequestMessages => _requestMessages.Where(r => r.Handler is not null);
- public IEnumerable NotificationMessages =>
- _notificationMessages;
+ public IEnumerable NotificationMessages => _notificationMessages;
- public IEnumerable RequestMessageHandlers =>
- _requestMessageHandlers;
+ public IEnumerable RequestMessageHandlers => _requestMessageHandlers;
public IEnumerable NotificationMessageHandlers =>
_notificationMessageHandlers.Where(h => !h.IsOpenGeneric);
@@ -51,9 +48,11 @@ internal sealed class CompilationAnalyzer
public bool HasCommands => _requestMessages.Any(r => r.Handler is not null && r.MessageType == "Command");
public bool HasQueries => _requestMessages.Any(r => r.Handler is not null && r.MessageType == "Query");
- public bool HasStreamRequests => _requestMessages.Any(r => r.Handler is not null && r.MessageType == "StreamRequest");
+ public bool HasStreamRequests =>
+ _requestMessages.Any(r => r.Handler is not null && r.MessageType == "StreamRequest");
public bool HasStreamQueries => _requestMessages.Any(r => r.Handler is not null && r.MessageType == "StreamQuery");
- public bool HasStreamCommands => _requestMessages.Any(r => r.Handler is not null && r.MessageType == "StreamCommand");
+ public bool HasStreamCommands =>
+ _requestMessages.Any(r => r.Handler is not null && r.MessageType == "StreamCommand");
public bool HasAnyRequest => HasRequests || HasCommands || HasQueries;
@@ -61,16 +60,24 @@ internal sealed class CompilationAnalyzer
public bool HasNotifications => _notificationMessages.Any();
- public IEnumerable IRequestMessages => _requestMessages.Where(r => r.Handler is not null && r.MessageType == "Request");
- public IEnumerable ICommandMessages => _requestMessages.Where(r => r.Handler is not null && r.MessageType == "Command");
- public IEnumerable IQueryMessages => _requestMessages.Where(r => r.Handler is not null && r.MessageType == "Query");
-
- public IEnumerable IStreamRequestMessages => _requestMessages.Where(r => r.Handler is not null && r.MessageType == "StreamRequest");
- public IEnumerable IStreamQueryMessages => _requestMessages.Where(r => r.Handler is not null && r.MessageType == "StreamQuery");
- public IEnumerable IStreamCommandMessages => _requestMessages.Where(r => r.Handler is not null && r.MessageType == "StreamCommand");
-
- public IEnumerable IMessages => _requestMessages.Where(r => r.Handler is not null && !r.IsStreaming);
- public IEnumerable IStreamMessages => _requestMessages.Where(r => r.Handler is not null && r.IsStreaming);
+ public IEnumerable IRequestMessages =>
+ _requestMessages.Where(r => r.Handler is not null && r.MessageType == "Request");
+ public IEnumerable ICommandMessages =>
+ _requestMessages.Where(r => r.Handler is not null && r.MessageType == "Command");
+ public IEnumerable IQueryMessages =>
+ _requestMessages.Where(r => r.Handler is not null && r.MessageType == "Query");
+
+ public IEnumerable IStreamRequestMessages =>
+ _requestMessages.Where(r => r.Handler is not null && r.MessageType == "StreamRequest");
+ public IEnumerable IStreamQueryMessages =>
+ _requestMessages.Where(r => r.Handler is not null && r.MessageType == "StreamQuery");
+ public IEnumerable IStreamCommandMessages =>
+ _requestMessages.Where(r => r.Handler is not null && r.MessageType == "StreamCommand");
+
+ public IEnumerable IMessages =>
+ _requestMessages.Where(r => r.Handler is not null && !r.IsStreaming);
+ public IEnumerable IStreamMessages =>
+ _requestMessages.Where(r => r.Handler is not null && r.IsStreaming);
private bool _hasErrors;
@@ -99,8 +106,9 @@ internal sealed class CompilationAnalyzer
public bool ServiceLifetimeIsTransient => ServiceLifetimeSymbol.Name == "Transient";
- public bool IsTestRun => (_context.Compilation.AssemblyName?.StartsWith("Mediator.Tests") ?? false) ||
- (_context.Compilation.AssemblyName?.StartsWith("Mediator.SmokeTest") ?? false);
+ public bool IsTestRun =>
+ (_context.Compilation.AssemblyName?.StartsWith("Mediator.Tests") ?? false)
+ || (_context.Compilation.AssemblyName?.StartsWith("Mediator.SmokeTest") ?? false);
public CompilationAnalyzer(in CompilationAnalyzerContext context)
{
@@ -139,7 +147,10 @@ private void TryLoadUnitSymbol(out INamedTypeSymbol UnitSymbol)
if (unitSymbol is null)
{
UnitSymbol = null!;
- ReportDiagnostic(unitSymbolName, ((in CompilationAnalyzerContext c, string name) => c.ReportRequiredSymbolNotFound(name)));
+ ReportDiagnostic(
+ unitSymbolName,
+ ((in CompilationAnalyzerContext c, string name) => c.ReportRequiredSymbolNotFound(name))
+ );
}
else
{
@@ -151,16 +162,20 @@ private void TryLoadBaseHandlerSymbols(out INamedTypeSymbol[] _baseHandlerSymbol
{
var baseHandlerSymbolNames = new[]
{
- $"{Constants.MediatorLib}.IRequestHandler`1", $"{Constants.MediatorLib}.IRequestHandler`2",
- $"{Constants.MediatorLib}.IStreamRequestHandler`2", $"{Constants.MediatorLib}.ICommandHandler`1",
- $"{Constants.MediatorLib}.ICommandHandler`2", $"{Constants.MediatorLib}.IStreamCommandHandler`2",
- $"{Constants.MediatorLib}.IQueryHandler`2", $"{Constants.MediatorLib}.IStreamQueryHandler`2",
+ $"{Constants.MediatorLib}.IRequestHandler`1",
+ $"{Constants.MediatorLib}.IRequestHandler`2",
+ $"{Constants.MediatorLib}.IStreamRequestHandler`2",
+ $"{Constants.MediatorLib}.ICommandHandler`1",
+ $"{Constants.MediatorLib}.ICommandHandler`2",
+ $"{Constants.MediatorLib}.IStreamCommandHandler`2",
+ $"{Constants.MediatorLib}.IQueryHandler`2",
+ $"{Constants.MediatorLib}.IStreamQueryHandler`2",
$"{Constants.MediatorLib}.INotificationHandler`1",
};
- var baseHandlerSymbols =
- baseHandlerSymbolNames.Select(n => (Name: n, Symbol: _context.Compilation.GetTypeByMetadataName(n)?.OriginalDefinition))
- .ToArray();
+ var baseHandlerSymbols = baseHandlerSymbolNames
+ .Select(n => (Name: n, Symbol: _context.Compilation.GetTypeByMetadataName(n)?.OriginalDefinition))
+ .ToArray();
_baseHandlerSymbols = Array.Empty();
if (baseHandlerSymbols.Any(s => s.Symbol is null))
@@ -169,18 +184,22 @@ private void TryLoadBaseHandlerSymbols(out INamedTypeSymbol[] _baseHandlerSymbol
{
if (symbol is not null)
continue;
- ReportDiagnostic(name, ((in CompilationAnalyzerContext c, string name) => c.ReportRequiredSymbolNotFound(name)));
+ ReportDiagnostic(
+ name,
+ ((in CompilationAnalyzerContext c, string name) => c.ReportRequiredSymbolNotFound(name))
+ );
}
}
else
{
- _baseHandlerSymbols = baseHandlerSymbols
- .Select(s => s.Symbol!)
- .ToArray();
+ _baseHandlerSymbols = baseHandlerSymbols.Select(s => s.Symbol!).ToArray();
}
}
- private void TryLoadDISymbols(out INamedTypeSymbol _serviceLifetimeEnumSymbol, out IFieldSymbol SingletonServiceLifetimeSymbol)
+ private void TryLoadDISymbols(
+ out INamedTypeSymbol _serviceLifetimeEnumSymbol,
+ out IFieldSymbol SingletonServiceLifetimeSymbol
+ )
{
var serviceLifetimeEnumSymbolName = "Microsoft.Extensions.DependencyInjection.ServiceLifetime";
var serviceLifetimeEnumSymbol = _context.Compilation.GetTypeByMetadataName(serviceLifetimeEnumSymbolName);
@@ -188,28 +207,40 @@ private void TryLoadDISymbols(out INamedTypeSymbol _serviceLifetimeEnumSymbol, o
{
_serviceLifetimeEnumSymbol = null!;
SingletonServiceLifetimeSymbol = null!;
- ReportDiagnostic(serviceLifetimeEnumSymbolName, ((in CompilationAnalyzerContext c, string name) => c.ReportRequiredSymbolNotFound(name)));
+ ReportDiagnostic(
+ serviceLifetimeEnumSymbolName,
+ ((in CompilationAnalyzerContext c, string name) => c.ReportRequiredSymbolNotFound(name))
+ );
}
else
{
_serviceLifetimeEnumSymbol = serviceLifetimeEnumSymbol;
- SingletonServiceLifetimeSymbol = (IFieldSymbol)_serviceLifetimeEnumSymbol.GetMembers().Single(m => m.Name == "Singleton");
+ SingletonServiceLifetimeSymbol = (IFieldSymbol)_serviceLifetimeEnumSymbol
+ .GetMembers()
+ .Single(m => m.Name == "Singleton");
}
}
- private void TryLoadBaseMessageSymbols(out INamedTypeSymbol[] _baseMessageSymbols, out INamedTypeSymbol _notificationInterfaceSymbol)
+ private void TryLoadBaseMessageSymbols(
+ out INamedTypeSymbol[] _baseMessageSymbols,
+ out INamedTypeSymbol _notificationInterfaceSymbol
+ )
{
var baseMessageSymbolNames = new[]
{
- $"{Constants.MediatorLib}.IRequest", $"{Constants.MediatorLib}.IRequest`1",
- $"{Constants.MediatorLib}.IStreamRequest`1", $"{Constants.MediatorLib}.ICommand",
- $"{Constants.MediatorLib}.ICommand`1", $"{Constants.MediatorLib}.IStreamCommand`1",
- $"{Constants.MediatorLib}.IQuery`1", $"{Constants.MediatorLib}.IStreamQuery`1",
+ $"{Constants.MediatorLib}.IRequest",
+ $"{Constants.MediatorLib}.IRequest`1",
+ $"{Constants.MediatorLib}.IStreamRequest`1",
+ $"{Constants.MediatorLib}.ICommand",
+ $"{Constants.MediatorLib}.ICommand`1",
+ $"{Constants.MediatorLib}.IStreamCommand`1",
+ $"{Constants.MediatorLib}.IQuery`1",
+ $"{Constants.MediatorLib}.IStreamQuery`1",
$"{Constants.MediatorLib}.INotification",
};
- var baseMessageSymbols =
- baseMessageSymbolNames.Select(n => (Name: n, Symbol: _context.Compilation.GetTypeByMetadataName(n)?.OriginalDefinition))
- .ToArray();
+ var baseMessageSymbols = baseMessageSymbolNames
+ .Select(n => (Name: n, Symbol: _context.Compilation.GetTypeByMetadataName(n)?.OriginalDefinition))
+ .ToArray();
_baseMessageSymbols = Array.Empty();
if (baseMessageSymbols.Any(s => s.Symbol is null))
@@ -219,14 +250,15 @@ private void TryLoadBaseMessageSymbols(out INamedTypeSymbol[] _baseMessageSymbol
{
if (symbol is not null)
continue;
- ReportDiagnostic(name, ((in CompilationAnalyzerContext c, string name) => c.ReportRequiredSymbolNotFound(name)));
+ ReportDiagnostic(
+ name,
+ ((in CompilationAnalyzerContext c, string name) => c.ReportRequiredSymbolNotFound(name))
+ );
}
}
else
{
- _baseMessageSymbols = baseMessageSymbols
- .Select(s => s.Symbol!)
- .ToArray();
+ _baseMessageSymbols = baseMessageSymbols.Select(s => s.Symbol!).ToArray();
_notificationInterfaceSymbol = _baseMessageSymbols[_baseMessageSymbols.Length - 1];
}
}
@@ -284,12 +316,17 @@ private void PopulateMetadata(Queue queue)
if (kvp.Value is not RequestMessage message)
continue;
- ReportDiagnostic(message.Symbol, (in CompilationAnalyzerContext c, INamedTypeSymbol s) => c.ReportMessageWithoutHandler(s));
+ ReportDiagnostic(
+ message.Symbol,
+ (in CompilationAnalyzerContext c, INamedTypeSymbol s) => c.ReportMessageWithoutHandler(s)
+ );
}
foreach (var notificationMessage in _notificationMessages)
{
- var handlerInterface = _baseHandlerSymbols[_baseHandlerSymbols.Length - 1].Construct(notificationMessage.Symbol);
+ var handlerInterface = _baseHandlerSymbols[_baseHandlerSymbols.Length - 1].Construct(
+ notificationMessage.Symbol
+ );
foreach (var notificationMessageHandler in _notificationMessageHandlers)
{
@@ -319,7 +356,11 @@ private void PopulateMetadata(Queue queue)
const int IS_REQUEST = 3;
const int IS_NOTIFICATION = 4;
- void ProcessMember(Queue queue, INamespaceOrTypeSymbol member, Dictionary mapping)
+ void ProcessMember(
+ Queue queue,
+ INamespaceOrTypeSymbol member,
+ Dictionary mapping
+ )
{
if (member is INamespaceSymbol childNsSymbol)
{
@@ -351,19 +392,30 @@ void ProcessMember(Queue queue, INamespaceOrTypeSymbol m
}
}
- bool ProcessInterface(int i, INamedTypeSymbol typeSymbol, INamedTypeSymbol typeInterfaceSymbol, bool isStruct, Dictionary mapping)
+ bool ProcessInterface(
+ int i,
+ INamedTypeSymbol typeSymbol,
+ INamedTypeSymbol typeInterfaceSymbol,
+ bool isStruct,
+ Dictionary mapping
+ )
{
var codeOfInterest = IsInteresting(typeInterfaceSymbol);
switch (codeOfInterest)
{
- case NOT_RELEVANT: break; // Continue loop
+ case NOT_RELEVANT:
+ break; // Continue loop
case IS_REQUEST_HANDLER:
case IS_NOTIFICATION_HANDLER:
+
{
if (isStruct)
{
// Handlers must be classes
- ReportDiagnostic(typeSymbol, (in CompilationAnalyzerContext c, INamedTypeSymbol s) => c.ReportInvalidHandlerType(s));
+ ReportDiagnostic(
+ typeSymbol,
+ (in CompilationAnalyzerContext c, INamedTypeSymbol s) => c.ReportInvalidHandlerType(s)
+ );
return false;
}
@@ -378,11 +430,18 @@ bool ProcessInterface(int i, INamedTypeSymbol typeSymbol, INamedTypeSymbol typeI
if (IsOpenGeneric(typeSymbol))
{
// Handlers must be classes
- ReportDiagnostic(typeSymbol, (in CompilationAnalyzerContext c, INamedTypeSymbol s) => c.ReportOpenGenericRequestHandler(s));
+ ReportDiagnostic(
+ typeSymbol,
+ (in CompilationAnalyzerContext c, INamedTypeSymbol s) =>
+ c.ReportOpenGenericRequestHandler(s)
+ );
return false;
}
- var messageType = typeInterfaceSymbol.Name.Substring(1, typeInterfaceSymbol.Name.IndexOf("Handler") - 1);
+ var messageType = typeInterfaceSymbol.Name.Substring(
+ 1,
+ typeInterfaceSymbol.Name.IndexOf("Handler") - 1
+ );
var handler = new RequestMessageHandler(typeSymbol, messageType, this);
var requestMessageSymbol = (INamedTypeSymbol)typeInterfaceSymbol.TypeArguments[0];
@@ -391,7 +450,11 @@ bool ProcessInterface(int i, INamedTypeSymbol typeSymbol, INamedTypeSymbol typeI
if (requestMessageObj is not RequestMessage requestMessage)
{
// Signal that we have duplicates
- ReportDiagnostic(typeSymbol, (in CompilationAnalyzerContext c, INamedTypeSymbol s) => c.ReportMultipleHandlers(s));
+ ReportDiagnostic(
+ typeSymbol,
+ (in CompilationAnalyzerContext c, INamedTypeSymbol s) =>
+ c.ReportMultipleHandlers(s)
+ );
return false;
}
mapping[requestMessageSymbol] = null;
@@ -411,24 +474,31 @@ bool ProcessInterface(int i, INamedTypeSymbol typeSymbol, INamedTypeSymbol typeI
}
break;
case IS_REQUEST:
+
{
- var responseMessageSymbol = typeInterfaceSymbol.TypeArguments.Length > 0 ?
- (INamedTypeSymbol)typeInterfaceSymbol.TypeArguments[0] :
- UnitSymbol;
+ var responseMessageSymbol =
+ typeInterfaceSymbol.TypeArguments.Length > 0
+ ? (INamedTypeSymbol)typeInterfaceSymbol.TypeArguments[0]
+ : UnitSymbol;
if (IsAlreadyHandledByDerivedInterface(i, 0, typeSymbol, typeInterfaceSymbol))
break;
- var messageType = typeInterfaceSymbol.Name.IndexOf('<') == -1 ?
- typeInterfaceSymbol.Name.Substring(1) :
- typeInterfaceSymbol.Name.Substring(1, typeInterfaceSymbol.Name.IndexOf('<') - 1);
+ var messageType =
+ typeInterfaceSymbol.Name.IndexOf('<') == -1
+ ? typeInterfaceSymbol.Name.Substring(1)
+ : typeInterfaceSymbol.Name.Substring(1, typeInterfaceSymbol.Name.IndexOf('<') - 1);
var message = new RequestMessage(typeSymbol, responseMessageSymbol, messageType, this);
if (!_requestMessages.Add(message))
{
// If this symbol has already been added,
// the type implements multiple base message types.
- ReportDiagnostic(typeSymbol, (in CompilationAnalyzerContext c, INamedTypeSymbol s) => c.ReportMessageDerivesFromMultipleMessageInterfaces(s));
+ ReportDiagnostic(
+ typeSymbol,
+ (in CompilationAnalyzerContext c, INamedTypeSymbol s) =>
+ c.ReportMessageDerivesFromMultipleMessageInterfaces(s)
+ );
return false;
}
else
@@ -446,12 +516,17 @@ bool ProcessInterface(int i, INamedTypeSymbol typeSymbol, INamedTypeSymbol typeI
}
break;
case IS_NOTIFICATION:
+
{
if (!_notificationMessages.Add(new NotificationMessage(typeSymbol, this)))
{
// If this symbol has already been added,
// the type implements multiple base message types.
- ReportDiagnostic(typeSymbol, (in CompilationAnalyzerContext c, INamedTypeSymbol s) => c.ReportMessageDerivesFromMultipleMessageInterfaces(s));
+ ReportDiagnostic(
+ typeSymbol,
+ (in CompilationAnalyzerContext c, INamedTypeSymbol s) =>
+ c.ReportMessageDerivesFromMultipleMessageInterfaces(s)
+ );
return false;
}
}
@@ -469,18 +544,18 @@ int IsInteresting(INamedTypeSymbol interfaceSymbol)
{
var baseSymbol = _baseHandlerSymbols[i];
if (_symbolComparer.Equals(baseSymbol, originalInterfaceSymbol))
- return _symbolComparer.Equals(baseSymbol, _notificationHandlerInterfaceSymbol) ?
- IS_NOTIFICATION_HANDLER :
- IS_REQUEST_HANDLER;
+ return _symbolComparer.Equals(baseSymbol, _notificationHandlerInterfaceSymbol)
+ ? IS_NOTIFICATION_HANDLER
+ : IS_REQUEST_HANDLER;
}
for (int i = 0; i < _baseMessageSymbols.Length; i++)
{
var baseSymbol = _baseMessageSymbols[i];
if (_symbolComparer.Equals(baseSymbol, originalInterfaceSymbol))
- return _symbolComparer.Equals(baseSymbol, _notificationInterfaceSymbol) ?
- IS_NOTIFICATION :
- IS_REQUEST;
+ return _symbolComparer.Equals(baseSymbol, _notificationInterfaceSymbol)
+ ? IS_NOTIFICATION
+ : IS_REQUEST;
}
return NOT_RELEVANT;
@@ -493,9 +568,10 @@ bool IsAlreadyHandledByDerivedInterface(
INamedTypeSymbol typeInterfaceSymbol
)
{
- var mightSkip = typeInterfaceSymbol.TypeArguments.Length > responseTypeArgumentIndex &&
- typeInterfaceSymbol.TypeArguments[responseTypeArgumentIndex] is INamedTypeSymbol responseTypeSymbol &&
- _symbolComparer.Equals(responseTypeSymbol, UnitSymbol);
+ var mightSkip =
+ typeInterfaceSymbol.TypeArguments.Length > responseTypeArgumentIndex
+ && typeInterfaceSymbol.TypeArguments[responseTypeArgumentIndex] is INamedTypeSymbol responseTypeSymbol
+ && _symbolComparer.Equals(responseTypeSymbol, UnitSymbol);
if (!mightSkip)
return false;
@@ -532,13 +608,16 @@ private void TryParseConfiguration(CancellationToken cancellationToken)
}
var attrs = compilation.Assembly.GetAttributes();
- var optionsAttr = attrs.SingleOrDefault(a =>
- {
- if (a.AttributeClass is null)
- return false;
- var attributeFullName = a.AttributeClass.GetTypeSymbolFullName(withGlobalPrefix: false);
- return attributeFullName == "Mediator.MediatorOptionsAttribute" || attributeFullName == "MediatorOptions";
- });
+ var optionsAttr = attrs.SingleOrDefault(
+ a =>
+ {
+ if (a.AttributeClass is null)
+ return false;
+ var attributeFullName = a.AttributeClass.GetTypeSymbolFullName(withGlobalPrefix: false);
+ return attributeFullName == "Mediator.MediatorOptionsAttribute"
+ || attributeFullName == "MediatorOptions";
+ }
+ );
if (optionsAttr is not null)
ProcessAttributeConfiguration(optionsAttr, configuredByAddMediator, cancellationToken);
}
@@ -598,7 +677,11 @@ CancellationToken cancellationToken
}
}
- private void ProcessAttributeConfiguration(AttributeData optionsAttr, bool configuredByAddMediator, CancellationToken cancellationToken)
+ private void ProcessAttributeConfiguration(
+ AttributeData optionsAttr,
+ bool configuredByAddMediator,
+ CancellationToken cancellationToken
+ )
{
var compilation = _context.Compilation;
@@ -625,19 +708,30 @@ private void ProcessAttributeConfiguration(AttributeData optionsAttr, bool confi
var attrFieldName = attrArg.NameEquals.Name.ToString();
if (attrFieldName == "ServiceLifetime")
{
- var identifierNameSyntax = (IdentifierNameSyntax)((MemberAccessExpressionSyntax)attrArg.Expression).Name;
- _configuredLifetimeSymbol = GetServiceLifetimeSymbol(identifierNameSyntax, semanticModel, cancellationToken);
+ var identifierNameSyntax = (IdentifierNameSyntax)(
+ (MemberAccessExpressionSyntax)attrArg.Expression
+ ).Name;
+ _configuredLifetimeSymbol = GetServiceLifetimeSymbol(
+ identifierNameSyntax,
+ semanticModel,
+ cancellationToken
+ );
}
else if (attrFieldName == "Namespace")
{
- var namespaceArg = semanticModel.GetConstantValue(attrArg.Expression, cancellationToken).Value as string;
+ var namespaceArg =
+ semanticModel.GetConstantValue(attrArg.Expression, cancellationToken).Value as string;
if (!string.IsNullOrWhiteSpace(namespaceArg))
MediatorNamespace = namespaceArg!;
}
}
}
- private bool ProcessAddMediatorAssignmentStatement(AssignmentExpressionSyntax assignment, SemanticModel semanticModel, CancellationToken cancellationToken)
+ private bool ProcessAddMediatorAssignmentStatement(
+ AssignmentExpressionSyntax assignment,
+ SemanticModel semanticModel,
+ CancellationToken cancellationToken
+ )
{
var opt = ((MemberAccessExpressionSyntax)assignment.Left).Name.Identifier.Text;
if (opt == "Namespace")
@@ -671,7 +765,11 @@ private bool ProcessAddMediatorAssignmentStatement(AssignmentExpressionSyntax as
if (assignment.Right is MemberAccessExpressionSyntax enumAccess)
{
var identifierNameSyntax = (IdentifierNameSyntax)enumAccess.Name;
- _configuredLifetimeSymbol = GetServiceLifetimeSymbol(identifierNameSyntax, semanticModel, cancellationToken);
+ _configuredLifetimeSymbol = GetServiceLifetimeSymbol(
+ identifierNameSyntax,
+ semanticModel,
+ cancellationToken
+ );
}
else if (assignment.Right is IdentifierNameSyntax identifier)
{
@@ -691,8 +789,11 @@ private bool ProcessAddMediatorAssignmentStatement(AssignmentExpressionSyntax as
return true;
-
- string? TryResolveNamespaceIdentifier(IdentifierNameSyntax identifier, SemanticModel semanticModel, CancellationToken cancellationToken)
+ string? TryResolveNamespaceIdentifier(
+ IdentifierNameSyntax identifier,
+ SemanticModel semanticModel,
+ CancellationToken cancellationToken
+ )
{
var variableSymbol = semanticModel.GetSymbolInfo(identifier, cancellationToken).Symbol;
if (variableSymbol is null)
@@ -708,7 +809,11 @@ private bool ProcessAddMediatorAssignmentStatement(AssignmentExpressionSyntax as
return null;
}
- string? TryResolveNamespaceSymbol(ISymbol symbol, SemanticModel semanticModel, CancellationToken cancellationToken)
+ string? TryResolveNamespaceSymbol(
+ ISymbol symbol,
+ SemanticModel semanticModel,
+ CancellationToken cancellationToken
+ )
{
if (symbol is IFieldSymbol fieldSymbol && fieldSymbol.HasConstantValue)
return fieldSymbol.ConstantValue as string;
@@ -718,11 +823,11 @@ private bool ProcessAddMediatorAssignmentStatement(AssignmentExpressionSyntax as
var syntaxReferences = symbol.DeclaringSyntaxReferences;
var syntaxNode = syntaxReferences.First().GetSyntax(cancellationToken);
- var initializerExpression = syntaxNode is VariableDeclaratorSyntax variableDeclarator ?
- variableDeclarator.Initializer?.Value :
- syntaxNode is PropertyDeclarationSyntax propertyDeclaration ?
- propertyDeclaration.Initializer?.Value :
- null;
+ var initializerExpression = syntaxNode is VariableDeclaratorSyntax variableDeclarator
+ ? variableDeclarator.Initializer?.Value
+ : syntaxNode is PropertyDeclarationSyntax propertyDeclaration
+ ? propertyDeclaration.Initializer?.Value
+ : null;
if (initializerExpression is null)
{
@@ -740,10 +845,17 @@ syntaxNode is PropertyDeclarationSyntax propertyDeclaration ?
}
}
- private IFieldSymbol? GetServiceLifetimeSymbol(IdentifierNameSyntax identifierNameSyntax, SemanticModel semanticModel, CancellationToken cancellationToken)
+ private IFieldSymbol? GetServiceLifetimeSymbol(
+ IdentifierNameSyntax identifierNameSyntax,
+ SemanticModel semanticModel,
+ CancellationToken cancellationToken
+ )
{
var symbol = semanticModel.GetSymbolInfo(identifierNameSyntax, cancellationToken).Symbol;
- if (symbol is IFieldSymbol lifetimeSymbol && SymbolEqualityComparer.Default.Equals(_serviceLifetimeEnumSymbol, lifetimeSymbol.ContainingType))
+ if (
+ symbol is IFieldSymbol lifetimeSymbol
+ && SymbolEqualityComparer.Default.Equals(_serviceLifetimeEnumSymbol, lifetimeSymbol.ContainingType)
+ )
return lifetimeSymbol;
if (symbol is IFieldSymbol fieldSymbol)
@@ -756,27 +868,37 @@ syntaxNode is PropertyDeclarationSyntax propertyDeclaration ?
return null;
}
- private IFieldSymbol? TryGetServiceLifetimeSymbol(ISymbol symbol, SemanticModel semanticModel, CancellationToken cancellationToken)
+ private IFieldSymbol? TryGetServiceLifetimeSymbol(
+ ISymbol symbol,
+ SemanticModel semanticModel,
+ CancellationToken cancellationToken
+ )
{
if (symbol is IFieldSymbol fieldSymbol && fieldSymbol.HasConstantValue)
{
var value = (int)fieldSymbol.ConstantValue!;
- return _serviceLifetimeEnumSymbol.GetMembers().OfType().Single(m => (int)m.ConstantValue! == value);
+ return _serviceLifetimeEnumSymbol
+ .GetMembers()
+ .OfType()
+ .Single(m => (int)m.ConstantValue! == value);
}
if (symbol is ILocalSymbol localSymbol && localSymbol.HasConstantValue)
{
var value = (int)localSymbol.ConstantValue!;
- return _serviceLifetimeEnumSymbol.GetMembers().OfType().Single(m => (int)m.ConstantValue! == value);
+ return _serviceLifetimeEnumSymbol
+ .GetMembers()
+ .OfType()
+ .Single(m => (int)m.ConstantValue! == value);
}
var syntaxReferences = symbol.DeclaringSyntaxReferences;
var syntaxNode = syntaxReferences.First().GetSyntax(cancellationToken);
- var initializerExpression = syntaxNode is VariableDeclaratorSyntax variableDeclarator ?
- variableDeclarator.Initializer?.Value :
- syntaxNode is PropertyDeclarationSyntax propertyDeclaration ?
- propertyDeclaration.Initializer?.Value :
- null;
+ var initializerExpression = syntaxNode is VariableDeclaratorSyntax variableDeclarator
+ ? variableDeclarator.Initializer?.Value
+ : syntaxNode is PropertyDeclarationSyntax propertyDeclaration
+ ? propertyDeclaration.Initializer?.Value
+ : null;
if (initializerExpression is null)
{
@@ -787,7 +909,10 @@ syntaxNode is PropertyDeclarationSyntax propertyDeclaration ?
if (initializerExpression is LiteralExpressionSyntax literal)
{
var value = (int)literal.Token.Value!;
- return _serviceLifetimeEnumSymbol.GetMembers().OfType().Single(m => (int)m.ConstantValue! == value);
+ return _serviceLifetimeEnumSymbol
+ .GetMembers()
+ .OfType()
+ .Single(m => (int)m.ConstantValue! == value);
}
if (initializerExpression is MemberAccessExpressionSyntax memberAccess)
@@ -800,6 +925,7 @@ syntaxNode is PropertyDeclarationSyntax propertyDeclaration ?
}
private delegate Diagnostic ReportDiagnosticDelegate(in CompilationAnalyzerContext context, T state);
+
private void ReportDiagnostic(T state, ReportDiagnosticDelegate del)
{
var diagnostic = del(in _context, state);
@@ -807,6 +933,7 @@ private void ReportDiagnostic(T state, ReportDiagnosticDelegate del)
}
private delegate Diagnostic ReportDiagnosticDelegate(in CompilationAnalyzerContext context);
+
private void ReportDiagnostic(ReportDiagnosticDelegate del)
{
var diagnostic = del(in _context);
diff --git a/src/Mediator.SourceGenerator.Implementation/Analysis/InvocationSyntaxReceiver.cs b/src/Mediator.SourceGenerator.Implementation/Analysis/InvocationSyntaxReceiver.cs
index 4a09cd0..1185707 100644
--- a/src/Mediator.SourceGenerator.Implementation/Analysis/InvocationSyntaxReceiver.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Analysis/InvocationSyntaxReceiver.cs
@@ -13,7 +13,10 @@ public void OnVisitSyntaxNode(SyntaxNode context)
public static bool ShouldVisit(SyntaxNode context, out InvocationExpressionSyntax? invocation)
{
invocation = null;
- if (context is not InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax identifier } invocationSyntax)
+ if (
+ context
+ is not InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax identifier } invocationSyntax
+ )
return false;
if (identifier.Name.Identifier.ValueText != "AddMediator")
return false;
diff --git a/src/Mediator.SourceGenerator.Implementation/Analysis/MessageHandler.cs b/src/Mediator.SourceGenerator.Implementation/Analysis/MessageHandler.cs
index ce6c761..daa33d4 100644
--- a/src/Mediator.SourceGenerator.Implementation/Analysis/MessageHandler.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Analysis/MessageHandler.cs
@@ -4,10 +4,7 @@ namespace Mediator.SourceGenerator;
internal abstract class MessageHandler : SymbolMetadata>
{
- protected MessageHandler(INamedTypeSymbol symbol, CompilationAnalyzer analyzer)
- : base(symbol, analyzer)
- {
- }
+ protected MessageHandler(INamedTypeSymbol symbol, CompilationAnalyzer analyzer) : base(symbol, analyzer) { }
public bool IsOpenGeneric => Symbol.TypeArguments.Length > 0;
diff --git a/src/Mediator.SourceGenerator.Implementation/Analysis/NotificationMessage.cs b/src/Mediator.SourceGenerator.Implementation/Analysis/NotificationMessage.cs
index 7c72cb4..cb79b8c 100644
--- a/src/Mediator.SourceGenerator.Implementation/Analysis/NotificationMessage.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Analysis/NotificationMessage.cs
@@ -6,8 +6,7 @@ internal sealed class NotificationMessage : SymbolMetadata
{
private readonly HashSet _handlers;
- public NotificationMessage(INamedTypeSymbol symbol, CompilationAnalyzer analyzer)
- : base(symbol, analyzer)
+ public NotificationMessage(INamedTypeSymbol symbol, CompilationAnalyzer analyzer) : base(symbol, analyzer)
{
_handlers = new();
}
@@ -16,13 +15,18 @@ public NotificationMessage(INamedTypeSymbol symbol, CompilationAnalyzer analyzer
public string FullName => Symbol.GetTypeSymbolFullName();
- public string IdentifierFullName => Symbol.GetTypeSymbolFullName(withGlobalPrefix: false, includeTypeParameters: false).Replace("global::", "").Replace('.', '_');
+ public string IdentifierFullName =>
+ Symbol
+ .GetTypeSymbolFullName(withGlobalPrefix: false, includeTypeParameters: false)
+ .Replace("global::", "")
+ .Replace('.', '_');
public int HandlerCount => _handlers.Count;
public string ServiceLifetime => Analyzer.ServiceLifetime;
- public string HandlerTypeOfExpression => $"typeof(global::Mediator.INotificationHandler<{Symbol.GetTypeSymbolFullName()}>)";
+ public string HandlerTypeOfExpression =>
+ $"typeof(global::Mediator.INotificationHandler<{Symbol.GetTypeSymbolFullName()}>)";
public IEnumerable HandlerServicesRegistrationBlock
{
diff --git a/src/Mediator.SourceGenerator.Implementation/Analysis/NotificationMessageHandler.cs b/src/Mediator.SourceGenerator.Implementation/Analysis/NotificationMessageHandler.cs
index e54a6a3..6162717 100644
--- a/src/Mediator.SourceGenerator.Implementation/Analysis/NotificationMessageHandler.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Analysis/NotificationMessageHandler.cs
@@ -2,13 +2,10 @@ namespace Mediator.SourceGenerator;
internal sealed class NotificationMessageHandler : MessageHandler
{
- public NotificationMessageHandler(INamedTypeSymbol symbol, CompilationAnalyzer analyzer)
- : base(symbol, analyzer)
- {
- }
+ public NotificationMessageHandler(INamedTypeSymbol symbol, CompilationAnalyzer analyzer) : base(symbol, analyzer)
+ { }
- public string OpenGenericTypeOfExpression =>
- $"typeof(global::Mediator.INotificationHandler<>)";
+ public string OpenGenericTypeOfExpression => $"typeof(global::Mediator.INotificationHandler<>)";
public string OpenGenericServiceRegistrationBlock =>
$"services.Add(new SD({OpenGenericTypeOfExpression}, {TypeOfExpression(false)}, {ServiceLifetime}));";
diff --git a/src/Mediator.SourceGenerator.Implementation/Analysis/RequestMessage.cs b/src/Mediator.SourceGenerator.Implementation/Analysis/RequestMessage.cs
index edc5390..d0378fa 100644
--- a/src/Mediator.SourceGenerator.Implementation/Analysis/RequestMessage.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Analysis/RequestMessage.cs
@@ -14,8 +14,12 @@ internal sealed class RequestMessage : SymbolMetadata
public bool IsStreaming => MessageType.StartsWith("Stream");
- public RequestMessage(INamedTypeSymbol symbol, INamedTypeSymbol responseSymbol, string messageType, CompilationAnalyzer analyzer)
- : base(symbol, analyzer)
+ public RequestMessage(
+ INamedTypeSymbol symbol,
+ INamedTypeSymbol responseSymbol,
+ string messageType,
+ CompilationAnalyzer analyzer
+ ) : base(symbol, analyzer)
{
ResponseSymbol = responseSymbol;
WrapperType = analyzer.RequestMessageHandlerWrappers.Single(w => w.MessageType == messageType);
@@ -30,20 +34,25 @@ public RequestMessage(INamedTypeSymbol symbol, INamedTypeSymbol responseSymbol,
public string HandlerWrapperTypeNameWithGenericTypeArguments =>
WrapperType.HandlerWrapperTypeNameWithGenericTypeArguments(Symbol, ResponseSymbol);
- public string PipelineHandlerType => IsStreaming ?
- $"global::Mediator.IStreamPipelineBehavior<{RequestFullName}, {ResponseFullName}>" :
- $"global::Mediator.IPipelineBehavior<{RequestFullName}, {ResponseFullName}>";
+ public string PipelineHandlerType =>
+ IsStreaming
+ ? $"global::Mediator.IStreamPipelineBehavior<{RequestFullName}, {ResponseFullName}>"
+ : $"global::Mediator.IPipelineBehavior<{RequestFullName}, {ResponseFullName}>";
- public string IdentifierFullName => Symbol.GetTypeSymbolFullName(withGlobalPrefix: false, includeTypeParameters: false).Replace("global::", "").Replace('.', '_');
+ public string IdentifierFullName =>
+ Symbol
+ .GetTypeSymbolFullName(withGlobalPrefix: false, includeTypeParameters: false)
+ .Replace("global::", "")
+ .Replace('.', '_');
- public string HandlerWrapperPropertyName =>
- $"Wrapper_For_{IdentifierFullName}";
+ public string HandlerWrapperPropertyName => $"Wrapper_For_{IdentifierFullName}";
public string SyncMethodName => IsStreaming ? "CreateStream" : "Send";
public string AsyncMethodName => IsStreaming ? "CreateStream" : "Send";
public string SyncReturnType => ResponseSymbol.GetTypeSymbolFullName();
- public string AsyncReturnType => IsStreaming ?
- $"global::System.Collections.Generic.IAsyncEnumerable<{ResponseFullName}>" :
- $"global::System.Threading.Tasks.ValueTask<{ResponseFullName}>";
+ public string AsyncReturnType =>
+ IsStreaming
+ ? $"global::System.Collections.Generic.IAsyncEnumerable<{ResponseFullName}>"
+ : $"global::System.Threading.Tasks.ValueTask<{ResponseFullName}>";
}
diff --git a/src/Mediator.SourceGenerator.Implementation/Analysis/RequestMessageHandlerWrapper.cs b/src/Mediator.SourceGenerator.Implementation/Analysis/RequestMessageHandlerWrapper.cs
index a60b99b..0a5ee8a 100644
--- a/src/Mediator.SourceGenerator.Implementation/Analysis/RequestMessageHandlerWrapper.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Analysis/RequestMessageHandlerWrapper.cs
@@ -13,23 +13,23 @@ public RequestMessageHandlerWrapper(string messageType, CompilationAnalyzer anal
_analyzer = analyzer;
}
- public string FullNamespace =>
- $"global::{_analyzer.MediatorNamespace}";
+ public string FullNamespace => $"global::{_analyzer.MediatorNamespace}";
public string HandlerWrapperTypeName(TypeKind type) =>
$"{MessageType}{(type == TypeKind.Struct ? "Struct" : "Class")}HandlerWrapper";
- public string HandlerWrapperTypeFullName(TypeKind type) =>
- $"{FullNamespace}.{HandlerWrapperTypeName(type)}";
+ public string HandlerWrapperTypeFullName(TypeKind type) => $"{FullNamespace}.{HandlerWrapperTypeName(type)}";
public string HandlerWrapperTypeNameWithGenericTypeArguments(TypeKind type) =>
$"{HandlerWrapperTypeName(type)}";
- public string HandlerWrapperTypeNameWithGenericTypeArguments(INamedTypeSymbol requestSymbol, INamedTypeSymbol responseSymbol) =>
+ public string HandlerWrapperTypeNameWithGenericTypeArguments(
+ INamedTypeSymbol requestSymbol,
+ INamedTypeSymbol responseSymbol
+ ) =>
$"{HandlerWrapperTypeFullName(requestSymbol.TypeKind)}<{requestSymbol.GetTypeSymbolFullName()}, {responseSymbol.GetTypeSymbolFullName()}>";
- public string HandlerWrapperTypeOfExpression(TypeKind type) =>
- $"typeof({HandlerWrapperTypeFullName(type)}<,>)";
+ public string HandlerWrapperTypeOfExpression(TypeKind type) => $"typeof({HandlerWrapperTypeFullName(type)}<,>)";
public string ClassHandlerWrapperTypeNameWithGenericTypeArguments =>
HandlerWrapperTypeNameWithGenericTypeArguments(TypeKind.Class);
@@ -37,20 +37,24 @@ public string HandlerWrapperTypeOfExpression(TypeKind type) =>
public string StructHandlerWrapperTypeNameWithGenericTypeArguments =>
HandlerWrapperTypeNameWithGenericTypeArguments(TypeKind.Struct);
- public string ClassHandlerWrapperTypeName =>
- HandlerWrapperTypeName(TypeKind.Class);
+ public string ClassHandlerWrapperTypeName => HandlerWrapperTypeName(TypeKind.Class);
- public string StructHandlerWrapperTypeName =>
- HandlerWrapperTypeName(TypeKind.Struct);
+ public string StructHandlerWrapperTypeName => HandlerWrapperTypeName(TypeKind.Struct);
public bool IsStreaming => MessageType.StartsWith("Stream");
- public string MessageHandlerDelegateName => IsStreaming ? $"global::Mediator.StreamHandlerDelegate" :
- $"global::Mediator.MessageHandlerDelegate";
+ public string MessageHandlerDelegateName =>
+ IsStreaming
+ ? $"global::Mediator.StreamHandlerDelegate"
+ : $"global::Mediator.MessageHandlerDelegate";
- public string PipelineHandlerTypeName => IsStreaming ? "global::Mediator.IStreamPipelineBehavior" :
- "global::Mediator.IPipelineBehavior";
+ public string PipelineHandlerTypeName =>
+ IsStreaming
+ ? "global::Mediator.IStreamPipelineBehavior"
+ : "global::Mediator.IPipelineBehavior";
- public string ReturnTypeName => IsStreaming ? "global::System.Collections.Generic.IAsyncEnumerable" :
- "global::System.Threading.Tasks.ValueTask";
+ public string ReturnTypeName =>
+ IsStreaming
+ ? "global::System.Collections.Generic.IAsyncEnumerable"
+ : "global::System.Threading.Tasks.ValueTask";
}
diff --git a/src/Mediator.SourceGenerator.Implementation/Analysis/SymbolMetadata.cs b/src/Mediator.SourceGenerator.Implementation/Analysis/SymbolMetadata.cs
index bfb7326..4d18357 100644
--- a/src/Mediator.SourceGenerator.Implementation/Analysis/SymbolMetadata.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Analysis/SymbolMetadata.cs
@@ -1,7 +1,6 @@
namespace Mediator.SourceGenerator;
-internal abstract class SymbolMetadata : IEquatable
- where T : SymbolMetadata
+internal abstract class SymbolMetadata : IEquatable where T : SymbolMetadata
{
private static readonly SymbolEqualityComparer _comparer = SymbolEqualityComparer.Default;
public readonly INamedTypeSymbol Symbol;
diff --git a/src/Mediator.SourceGenerator.Implementation/Diagnostics.cs b/src/Mediator.SourceGenerator.Implementation/Diagnostics.cs
index 19f2498..d28e2da 100644
--- a/src/Mediator.SourceGenerator.Implementation/Diagnostics.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Diagnostics.cs
@@ -21,7 +21,8 @@ static Diagnostics()
$"{nameof(MediatorGenerator)} got unknown error: " + "{0}",
nameof(MediatorGenerator),
DiagnosticSeverity.Error,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
MultipleHandlersError = new DiagnosticDescriptor(
GetNextId(),
@@ -29,7 +30,8 @@ static Diagnostics()
$"{nameof(MediatorGenerator)} found multiple handlers " + "of message type {0}",
nameof(MediatorGenerator),
DiagnosticSeverity.Warning,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
InvalidHandlerTypeError = new DiagnosticDescriptor(
GetNextId(),
@@ -37,15 +39,18 @@ static Diagnostics()
$"{nameof(MediatorGenerator)} found invalid handler type " + "{0}",
nameof(MediatorGenerator),
DiagnosticSeverity.Warning,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
OpenGenericRequestHandler = new DiagnosticDescriptor(
GetNextId(),
$"{nameof(MediatorGenerator)} invalid handler",
- $"{nameof(MediatorGenerator)} found invalid handler type, request/query/command handlers cannot be generic: " + "{0}",
+ $"{nameof(MediatorGenerator)} found invalid handler type, request/query/command handlers cannot be generic: "
+ + "{0}",
nameof(MediatorGenerator),
DiagnosticSeverity.Warning,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
MessageDerivesFromMultipleMessageInterfaces = new DiagnosticDescriptor(
GetNextId(),
@@ -53,7 +58,8 @@ static Diagnostics()
$"{nameof(MediatorGenerator)} found message that derives from multiple message interfaces: " + "{0}",
nameof(MediatorGenerator),
DiagnosticSeverity.Warning,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
MessageWithoutHandler = new DiagnosticDescriptor(
GetNextId(),
@@ -61,7 +67,8 @@ static Diagnostics()
$"{nameof(MediatorGenerator)} found message without any registered handler: " + "{0}",
nameof(MediatorGenerator),
DiagnosticSeverity.Warning,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
ConflictingConfiguration = new DiagnosticDescriptor(
GetNextId(),
@@ -69,7 +76,8 @@ static Diagnostics()
$"{nameof(MediatorGenerator)} found conflicting configuration - both MediatorOptions and MediatorOptionsAttribute configuration are being used.",
nameof(MediatorGenerator),
DiagnosticSeverity.Error,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
InvalidCodeBasedConfiguration = new DiagnosticDescriptor(
GetNextId(),
@@ -77,7 +85,8 @@ static Diagnostics()
$"{nameof(MediatorGenerator)} cannot parse MediatorOptions-based configuration. Only compile-time constant values can be used in MediatorOptions configuration.",
nameof(MediatorGenerator),
DiagnosticSeverity.Error,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
RequiredSymbolNotFound = new DiagnosticDescriptor(
GetNextId(),
@@ -85,7 +94,8 @@ static Diagnostics()
$"{nameof(MediatorGenerator)} could not find symbol required during analysis: {0}",
nameof(MediatorGenerator),
DiagnosticSeverity.Error,
- isEnabledByDefault: true);
+ isEnabledByDefault: true
+ );
static string GetNextId()
{
@@ -101,8 +111,7 @@ private static Diagnostic Report(
this CompilationAnalyzerContext context,
DiagnosticDescriptor diagnosticDescriptor,
T arg
- )
- where T : class
+ ) where T : class
{
Diagnostic diagnostic;
if (arg is ISymbol symbolArg)
@@ -119,10 +128,7 @@ T arg
return diagnostic;
}
- private static Diagnostic Report(
- this CompilationAnalyzerContext context,
- DiagnosticDescriptor diagnosticDescriptor
- )
+ private static Diagnostic Report(this CompilationAnalyzerContext context, DiagnosticDescriptor diagnosticDescriptor)
{
var diagnostic = Diagnostic.Create(diagnosticDescriptor, Location.None);
context.ReportDiagnostic(diagnostic);
@@ -130,38 +136,57 @@ DiagnosticDescriptor diagnosticDescriptor
}
public static readonly DiagnosticDescriptor GenericError;
+
internal static Diagnostic ReportGenericError(this CompilationAnalyzerContext context, Exception exception) =>
context.Report(GenericError, exception);
public static readonly DiagnosticDescriptor MultipleHandlersError;
- internal static Diagnostic ReportMultipleHandlers(this CompilationAnalyzerContext context, INamedTypeSymbol messageType) =>
- context.Report(MultipleHandlersError, messageType);
+
+ internal static Diagnostic ReportMultipleHandlers(
+ this CompilationAnalyzerContext context,
+ INamedTypeSymbol messageType
+ ) => context.Report(MultipleHandlersError, messageType);
public static readonly DiagnosticDescriptor InvalidHandlerTypeError;
- internal static Diagnostic ReportInvalidHandlerType(this CompilationAnalyzerContext context, INamedTypeSymbol handlerType) =>
- context.Report(InvalidHandlerTypeError, handlerType);
+
+ internal static Diagnostic ReportInvalidHandlerType(
+ this CompilationAnalyzerContext context,
+ INamedTypeSymbol handlerType
+ ) => context.Report(InvalidHandlerTypeError, handlerType);
public static readonly DiagnosticDescriptor OpenGenericRequestHandler;
- internal static Diagnostic ReportOpenGenericRequestHandler(this CompilationAnalyzerContext context, INamedTypeSymbol handlerType) =>
- context.Report(OpenGenericRequestHandler, handlerType);
+
+ internal static Diagnostic ReportOpenGenericRequestHandler(
+ this CompilationAnalyzerContext context,
+ INamedTypeSymbol handlerType
+ ) => context.Report(OpenGenericRequestHandler, handlerType);
public static readonly DiagnosticDescriptor MessageDerivesFromMultipleMessageInterfaces;
- internal static Diagnostic ReportMessageDerivesFromMultipleMessageInterfaces(this CompilationAnalyzerContext context, INamedTypeSymbol messageType) =>
- context.Report(MessageDerivesFromMultipleMessageInterfaces, messageType);
+
+ internal static Diagnostic ReportMessageDerivesFromMultipleMessageInterfaces(
+ this CompilationAnalyzerContext context,
+ INamedTypeSymbol messageType
+ ) => context.Report(MessageDerivesFromMultipleMessageInterfaces, messageType);
public static readonly DiagnosticDescriptor MessageWithoutHandler;
- internal static Diagnostic ReportMessageWithoutHandler(this CompilationAnalyzerContext context, INamedTypeSymbol messageType) =>
- context.Report(MessageWithoutHandler, messageType);
+
+ internal static Diagnostic ReportMessageWithoutHandler(
+ this CompilationAnalyzerContext context,
+ INamedTypeSymbol messageType
+ ) => context.Report(MessageWithoutHandler, messageType);
public static readonly DiagnosticDescriptor ConflictingConfiguration;
+
internal static Diagnostic ReportConflictingConfiguration(this CompilationAnalyzerContext context) =>
context.Report(ConflictingConfiguration);
public static readonly DiagnosticDescriptor InvalidCodeBasedConfiguration;
+
internal static Diagnostic ReportInvalidCodeBasedConfiguration(this CompilationAnalyzerContext context) =>
context.Report(InvalidCodeBasedConfiguration);
public static readonly DiagnosticDescriptor RequiredSymbolNotFound;
+
internal static Diagnostic ReportRequiredSymbolNotFound(this CompilationAnalyzerContext context, string name) =>
context.Report(RequiredSymbolNotFound, name);
}
diff --git a/src/Mediator.SourceGenerator.Implementation/EmbeddedResource.cs b/src/Mediator.SourceGenerator.Implementation/EmbeddedResource.cs
index c417da6..b2a7839 100644
--- a/src/Mediator.SourceGenerator.Implementation/EmbeddedResource.cs
+++ b/src/Mediator.SourceGenerator.Implementation/EmbeddedResource.cs
@@ -20,17 +20,22 @@ public static string GetContent(string relativePath)
.Replace(Path.DirectorySeparatorChar, '.')
.Replace(Path.AltDirectorySeparatorChar, '.');
- var manifestResourceName = Assembly.GetExecutingAssembly()
- .GetManifestResourceNames().FirstOrDefault(x => x!.EndsWith(resourceName, StringComparison.InvariantCulture));
+ var manifestResourceName = Assembly
+ .GetExecutingAssembly()
+ .GetManifestResourceNames()
+ .FirstOrDefault(x => x!.EndsWith(resourceName, StringComparison.InvariantCulture));
if (string.IsNullOrEmpty(manifestResourceName))
- throw new InvalidOperationException($"Did not find required resource ending in '{resourceName}' in assembly '{baseName}'.");
+ throw new InvalidOperationException(
+ $"Did not find required resource ending in '{resourceName}' in assembly '{baseName}'."
+ );
- using var stream = Assembly.GetExecutingAssembly()
- .GetManifestResourceStream(manifestResourceName);
+ using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName);
if (stream == null)
- throw new InvalidOperationException($"Did not find required resource '{manifestResourceName}' in assembly '{baseName}'.");
+ throw new InvalidOperationException(
+ $"Did not find required resource '{manifestResourceName}' in assembly '{baseName}'."
+ );
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
diff --git a/src/Mediator.SourceGenerator.Implementation/Extensions/IsExternalInit.cs b/src/Mediator.SourceGenerator.Implementation/Extensions/IsExternalInit.cs
index aabfe96..df23ad5 100644
--- a/src/Mediator.SourceGenerator.Implementation/Extensions/IsExternalInit.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Extensions/IsExternalInit.cs
@@ -7,7 +7,5 @@ namespace System.Runtime.CompilerServices
/// This class should not be used by developers in source code.
///
[EditorBrowsable(EditorBrowsableState.Never)]
- internal static class IsExternalInit
- {
- }
+ internal static class IsExternalInit { }
}
diff --git a/src/Mediator.SourceGenerator.Implementation/Extensions/RoslynExtensions.cs b/src/Mediator.SourceGenerator.Implementation/Extensions/RoslynExtensions.cs
index cbc89e7..9beeb78 100644
--- a/src/Mediator.SourceGenerator.Implementation/Extensions/RoslynExtensions.cs
+++ b/src/Mediator.SourceGenerator.Implementation/Extensions/RoslynExtensions.cs
@@ -2,14 +2,24 @@ namespace Mediator.SourceGenerator.Extensions;
public static class RoslynExtensions
{
- public static string GetTypeSymbolFullName(this ITypeSymbol symbol, bool withGlobalPrefix = true, bool includeTypeParameters = true)
+ public static string GetTypeSymbolFullName(
+ this ITypeSymbol symbol,
+ bool withGlobalPrefix = true,
+ bool includeTypeParameters = true
+ )
{
- return symbol.ToDisplayString(new SymbolDisplayFormat(
- withGlobalPrefix ? SymbolDisplayGlobalNamespaceStyle.Included : SymbolDisplayGlobalNamespaceStyle.Omitted,
- SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
- includeTypeParameters ? SymbolDisplayGenericsOptions.IncludeTypeParameters : SymbolDisplayGenericsOptions.None,
- miscellaneousOptions: SymbolDisplayMiscellaneousOptions.ExpandNullable
- ));
+ return symbol.ToDisplayString(
+ new SymbolDisplayFormat(
+ withGlobalPrefix
+ ? SymbolDisplayGlobalNamespaceStyle.Included
+ : SymbolDisplayGlobalNamespaceStyle.Omitted,
+ SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
+ includeTypeParameters
+ ? SymbolDisplayGenericsOptions.IncludeTypeParameters
+ : SymbolDisplayGenericsOptions.None,
+ miscellaneousOptions: SymbolDisplayMiscellaneousOptions.ExpandNullable
+ )
+ );
}
public static string GetFieldSymbolFullName(this IFieldSymbol symbol)
diff --git a/src/Mediator.SourceGenerator.Implementation/MediatorGenerationContext.cs b/src/Mediator.SourceGenerator.Implementation/MediatorGenerationContext.cs
index 45f8d09..4973d7b 100644
--- a/src/Mediator.SourceGenerator.Implementation/MediatorGenerationContext.cs
+++ b/src/Mediator.SourceGenerator.Implementation/MediatorGenerationContext.cs
@@ -6,7 +6,11 @@ internal readonly struct MediatorGenerationContext
public readonly IEnumerable HandlerTypes;
public readonly string MediatorNamespace;
- public MediatorGenerationContext(IReadOnlyDictionary> handlerMap, IEnumerable handlerTypes, string mediatorNamespace)
+ public MediatorGenerationContext(
+ IReadOnlyDictionary> handlerMap,
+ IEnumerable handlerTypes,
+ string mediatorNamespace
+ )
{
HandlerMap = handlerMap;
HandlerTypes = handlerTypes;
diff --git a/src/Mediator.SourceGenerator.Roslyn38/MediatorGenerator.cs b/src/Mediator.SourceGenerator.Roslyn38/MediatorGenerator.cs
index 513842d..f28b20d 100644
--- a/src/Mediator.SourceGenerator.Roslyn38/MediatorGenerator.cs
+++ b/src/Mediator.SourceGenerator.Roslyn38/MediatorGenerator.cs
@@ -7,7 +7,10 @@ public sealed class MediatorGenerator : ISourceGenerator
public void Execute(GeneratorExecutionContext context)
{
- var debugOptionExists = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.Mediator_AttachDebugger", out _);
+ var debugOptionExists = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue(
+ "build_property.Mediator_AttachDebugger",
+ out _
+ );
if (debugOptionExists && !System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Launch();
diff --git a/src/Mediator.SourceGenerator.Roslyn40/IncrementalMediatorGenerator.cs b/src/Mediator.SourceGenerator.Roslyn40/IncrementalMediatorGenerator.cs
index 57d0235..00b590a 100644
--- a/src/Mediator.SourceGenerator.Roslyn40/IncrementalMediatorGenerator.cs
+++ b/src/Mediator.SourceGenerator.Roslyn40/IncrementalMediatorGenerator.cs
@@ -13,7 +13,6 @@ private void ExecuteInternal(
IReadOnlyList addMediatorCalls
)
{
-
var generatorVersion = Versioning.GetVersion();
var analyzerContext = new CompilationAnalyzerContext(
@@ -39,12 +38,14 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
{
//System.Diagnostics.Debugger.Launch();
- context.RegisterPostInitializationOutput(context =>
- {
- var generatorVersion = Versioning.GetVersion();
+ context.RegisterPostInitializationOutput(
+ context =>
+ {
+ var generatorVersion = Versioning.GetVersion();
- MediatorOptionsGenerator.Generate(context.AddSource, generatorVersion);
- });
+ MediatorOptionsGenerator.Generate(context.AddSource, generatorVersion);
+ }
+ );
var compilationProvider = context.CompilationProvider;
var addMediatorCalls = context.SyntaxProvider.CreateSyntaxProvider(
@@ -55,9 +56,12 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
IncrementalValueProvider<(Compilation Compilation, ImmutableArray AddMediatorCalls)> source =
compilationProvider.Combine(addMediatorCalls.Collect());
- context.RegisterSourceOutput(source, (context, source) =>
- {
- ExecuteInternal(in context, source.Compilation, source.AddMediatorCalls);
- });
+ context.RegisterSourceOutput(
+ source,
+ (context, source) =>
+ {
+ ExecuteInternal(in context, source.Compilation, source.AddMediatorCalls);
+ }
+ );
}
}
diff --git a/src/Mediator/Handlers/ICommandHandler.cs b/src/Mediator/Handlers/ICommandHandler.cs
index 18c0820..e6b3eb1 100644
--- a/src/Mediator/Handlers/ICommandHandler.cs
+++ b/src/Mediator/Handlers/ICommandHandler.cs
@@ -1,12 +1,8 @@
namespace Mediator;
-public interface ICommandHandler
- where TCommand : ICommand
+public interface ICommandHandler where TCommand : ICommand
{
ValueTask Handle(TCommand command, CancellationToken cancellationToken);
}
-public interface ICommandHandler : ICommandHandler
- where TCommand : ICommand
-{
-}
+public interface ICommandHandler : ICommandHandler where TCommand : ICommand { }
diff --git a/src/Mediator/Handlers/INotificationHandler.cs b/src/Mediator/Handlers/INotificationHandler.cs
index f493176..c1e8cc1 100644
--- a/src/Mediator/Handlers/INotificationHandler.cs
+++ b/src/Mediator/Handlers/INotificationHandler.cs
@@ -1,7 +1,6 @@
namespace Mediator;
-public interface INotificationHandler
- where TNotification : INotification
+public interface INotificationHandler where TNotification : INotification
{
ValueTask Handle(TNotification notification, CancellationToken cancellationToken);
}
diff --git a/src/Mediator/Handlers/IQueryHandler.cs b/src/Mediator/Handlers/IQueryHandler.cs
index efbba8f..338108e 100644
--- a/src/Mediator/Handlers/IQueryHandler.cs
+++ b/src/Mediator/Handlers/IQueryHandler.cs
@@ -1,7 +1,6 @@
namespace Mediator;
-public interface IQueryHandler
- where TQuery : IQuery
+public interface IQueryHandler where TQuery : IQuery
{
ValueTask Handle(TQuery query, CancellationToken cancellationToken);
}
diff --git a/src/Mediator/Handlers/IRequestHandler.cs b/src/Mediator/Handlers/IRequestHandler.cs
index 2c8dcbf..fbfb77a 100644
--- a/src/Mediator/Handlers/IRequestHandler.cs
+++ b/src/Mediator/Handlers/IRequestHandler.cs
@@ -1,12 +1,8 @@
namespace Mediator;
-public interface IRequestHandler
- where TRequest : IRequest
+public interface IRequestHandler where TRequest : IRequest
{
ValueTask Handle(TRequest request, CancellationToken cancellationToken);
}
-public interface IRequestHandler : IRequestHandler
- where TRequest : IRequest
-{
-}
+public interface IRequestHandler : IRequestHandler where TRequest : IRequest { }
diff --git a/src/Mediator/Handlers/IStreamCommandHandler.cs b/src/Mediator/Handlers/IStreamCommandHandler.cs
index e16ed94..d744802 100644
--- a/src/Mediator/Handlers/IStreamCommandHandler.cs
+++ b/src/Mediator/Handlers/IStreamCommandHandler.cs
@@ -1,7 +1,6 @@
namespace Mediator;
-public interface IStreamCommandHandler
- where TCommand : IStreamCommand
+public interface IStreamCommandHandler where TCommand : IStreamCommand
{
IAsyncEnumerable Handle(TCommand command, CancellationToken cancellationToken);
}
diff --git a/src/Mediator/Handlers/IStreamQueryHandler.cs b/src/Mediator/Handlers/IStreamQueryHandler.cs
index 86353cf..7d85992 100644
--- a/src/Mediator/Handlers/IStreamQueryHandler.cs
+++ b/src/Mediator/Handlers/IStreamQueryHandler.cs
@@ -1,7 +1,6 @@
namespace Mediator;
-public interface IStreamQueryHandler
- where TQuery : IStreamQuery
+public interface IStreamQueryHandler where TQuery : IStreamQuery
{
IAsyncEnumerable Handle(TQuery query, CancellationToken cancellationToken);
}
diff --git a/src/Mediator/Handlers/IStreamRequestHandler.cs b/src/Mediator/Handlers/IStreamRequestHandler.cs
index 972c2b4..a0e6620 100644
--- a/src/Mediator/Handlers/IStreamRequestHandler.cs
+++ b/src/Mediator/Handlers/IStreamRequestHandler.cs
@@ -1,7 +1,6 @@
namespace Mediator;
-public interface IStreamRequestHandler
- where TRequest : IStreamRequest
+public interface IStreamRequestHandler where TRequest : IStreamRequest
{
IAsyncEnumerable Handle(TRequest request, CancellationToken cancellationToken);
}
diff --git a/src/Mediator/IMediator.cs b/src/Mediator/IMediator.cs
index 411729e..b511e3f 100644
--- a/src/Mediator/IMediator.cs
+++ b/src/Mediator/IMediator.cs
@@ -1,5 +1,3 @@
namespace Mediator;
-public interface IMediator : ISender, IPublisher
-{
-}
+public interface IMediator : ISender, IPublisher { }
diff --git a/src/Mediator/ISender.cs b/src/Mediator/ISender.cs
index f872396..3c5991b 100644
--- a/src/Mediator/ISender.cs
+++ b/src/Mediator/ISender.cs
@@ -10,11 +10,20 @@ public interface ISender
ValueTask