From f036747a2a81976586e0fe9afd001dcdf302b0fe Mon Sep 17 00:00:00 2001 From: Martin Othamar Date: Mon, 8 Apr 2024 21:53:54 +0200 Subject: [PATCH] Fix buggy code for ordering switch statement cases for messages (#147) --- .../Analysis/CompilationAnalyzer.cs | 68 +- .../Implementation/ImmutableEquatableArray.cs | 2 + .../MessageOrderingTests.cs | 64 +- ...ifications_Ordering#Mediator.g.verified.cs | 52 +- ...ons_Ordering_Bigger#Mediator.g.verified.cs | 1826 +++++++++++++++++ ...ering_Bigger#MediatorOptions.g.verified.cs | 33 + ...ger#MediatorOptionsAttribute.g.verified.cs | 34 + 7 files changed, 2025 insertions(+), 54 deletions(-) create mode 100644 test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#Mediator.g.verified.cs create mode 100644 test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#MediatorOptions.g.verified.cs create mode 100644 test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#MediatorOptionsAttribute.g.verified.cs diff --git a/src/Mediator.SourceGenerator/Implementation/Analysis/CompilationAnalyzer.cs b/src/Mediator.SourceGenerator/Implementation/Analysis/CompilationAnalyzer.cs index 3cf4197..51a972b 100644 --- a/src/Mediator.SourceGenerator/Implementation/Analysis/CompilationAnalyzer.cs +++ b/src/Mediator.SourceGenerator/Implementation/Analysis/CompilationAnalyzer.cs @@ -1,4 +1,6 @@ using System.Collections.Immutable; +using System.Diagnostics; +using System.Runtime.InteropServices.ComTypes; using Mediator.SourceGenerator.Extensions; using Microsoft.CodeAnalysis.CSharp; @@ -264,22 +266,35 @@ public void Analyze() } } - private sealed class InheritanceComparer : IComparer + private static ImmutableEquatableArray ToModelsSortedByInheritanceDepth( + HashSet source, + Func selector + ) + where TSource : SymbolMetadata + where TModel : SymbolMetadataModel, IEquatable { - public int Compare(INamedTypeSymbol x, INamedTypeSymbol y) + var analysis = new (TSource Message, int Depth)[source.Count]; + int i = 0; + foreach (var message in source) { - while (x.BaseType is not null) + var baseType = message.Symbol.BaseType; + int depth = 0; + while (baseType is not null && baseType.SpecialType != SpecialType.System_Object) { - if (x.BaseType.SpecialType == SpecialType.System_Object) - break; - - if (SymbolEqualityComparer.Default.Equals(x.BaseType, y)) - return -1; - x = x.BaseType; + depth++; + baseType = baseType.BaseType; } - return x.GetTypeSymbolFullName().CompareTo(y.GetTypeSymbolFullName()); + Debug.Assert(i < source.Count); + analysis[i++] = (message, depth); } + + Array.Sort(analysis, (x, y) => y.Depth.CompareTo(x.Depth)); + var models = new TModel[source.Count]; + for (i = 0; i < source.Count; i++) + models[i] = selector(analysis[i].Message); + + return new ImmutableEquatableArray(models); } public CompilationModel ToModel() @@ -289,28 +304,27 @@ public CompilationModel ToModel() try { - var comparer = new InheritanceComparer(); + if (_notificationPublisherImplementationSymbol is null) + throw new Exception("Unexpected state: NotificationPublisherImplementationSymbol is null"); + var model = new CompilationModel( - _requestMessages - .OrderBy(m => m.Symbol, comparer) - .Select(x => new RequestMessageModel( - x.Symbol, - x.ResponseSymbol, - x.MessageType, - x.Handler?.ToModel(), - x.WrapperType - )) - .ToImmutableEquatableArray(), - _notificationMessages - .OrderBy(m => m.Symbol, comparer) - .Select(x => x.ToModel()) - .ToImmutableEquatableArray(), + ToModelsSortedByInheritanceDepth( + _requestMessages, + m => new RequestMessageModel( + m.Symbol, + m.ResponseSymbol, + m.MessageType, + m.Handler?.ToModel(), + m.WrapperType + ) + ), + ToModelsSortedByInheritanceDepth(_notificationMessages, m => m.ToModel()), _requestMessageHandlers.Select(x => x.ToModel()).ToImmutableEquatableArray(), _notificationMessageHandlers.Select(x => x.ToModel()).ToImmutableEquatableArray(), RequestMessageHandlerWrappers.ToImmutableEquatableArray(), new NotificationPublisherTypeModel( - _notificationPublisherImplementationSymbol!.GetTypeSymbolFullName(), - _notificationPublisherImplementationSymbol!.Name + _notificationPublisherImplementationSymbol.GetTypeSymbolFullName(), + _notificationPublisherImplementationSymbol.Name ), HasErrors, MediatorNamespace, diff --git a/src/Mediator.SourceGenerator/Implementation/ImmutableEquatableArray.cs b/src/Mediator.SourceGenerator/Implementation/ImmutableEquatableArray.cs index 102b6d2..f1cf5cc 100644 --- a/src/Mediator.SourceGenerator/Implementation/ImmutableEquatableArray.cs +++ b/src/Mediator.SourceGenerator/Implementation/ImmutableEquatableArray.cs @@ -23,6 +23,8 @@ public sealed class ImmutableEquatableArray : IEquatable _values[index]; public int Count => _values.Length; + public ImmutableEquatableArray(T[] values) => _values = values; + public ImmutableEquatableArray(IEnumerable values) => _values = values.ToArray(); public bool Equals(ImmutableEquatableArray? other) => diff --git a/test/Mediator.SourceGenerator.Tests/MessageOrderingTests.cs b/test/Mediator.SourceGenerator.Tests/MessageOrderingTests.cs index ec75939..ae19a22 100644 --- a/test/Mediator.SourceGenerator.Tests/MessageOrderingTests.cs +++ b/test/Mediator.SourceGenerator.Tests/MessageOrderingTests.cs @@ -43,7 +43,7 @@ await inputCompilation.AssertAndVerify( Assert.Equal(5, notifications.Count); var last = notifications[^1]; - last.Name.Equals("DomainEvent"); + last.Name.Should().Be("DomainEvent"); var index0 = notifications.FindIndex(n => n.Name == "RoundSucceededActually"); var index1 = notifications.FindIndex(n => n.Name == "RoundSucceeded"); @@ -55,4 +55,66 @@ await inputCompilation.AssertAndVerify( } ); } + + [Fact] + public async Task Test_Notifications_Ordering_Bigger() + { + var inputCompilation = Fixture.CreateLibrary( + """ + using Mediator; + using System.Threading.Tasks; + using System; + + namespace TestCode; + + public class Program + { + public static void Main() + { + } + } + + public record DomainEvent(DateTimeOffset Timestamp) : INotification; + public record RoundCreated(long Id, DateTimeOffset Timestamp) : DomainEvent(Timestamp); + public record RoundResulted(long Id, long Win, DateTimeOffset Timestamp) : DomainEvent(Timestamp); + public record RoundSucceeded(long Id, DateTimeOffset Timestamp) : DomainEvent(Timestamp); + public record RoundSucceededActually(long Id, string Because, DateTimeOffset Timestamp) : RoundSucceeded(Id, Timestamp); + + public record DomainEvent2(DateTimeOffset Timestamp) : INotification; + public record Round2Created(long Id, DateTimeOffset Timestamp) : DomainEvent2(Timestamp); + public record Round2Resulted(long Id, long Win, DateTimeOffset Timestamp) : DomainEvent2(Timestamp); + public record Round2Succeeded(long Id, DateTimeOffset Timestamp) : DomainEvent2(Timestamp); + public record Round2SucceededActually(long Id, string Because, DateTimeOffset Timestamp) : RoundSucceeded(Id, Timestamp); + + public record DomainEvent10(DateTimeOffset Timestamp) : INotification; + public record Sound2Created(long Id, DateTimeOffset Timestamp) : DomainEvent10(Timestamp); + public record Sound2Resulted(long Id, long Win, DateTimeOffset Timestamp) : DomainEvent10(Timestamp); + public record Sound2Succeeded(long Id, DateTimeOffset Timestamp) : DomainEvent10(Timestamp); + public record Sound2SucceededActually(long Id, string Because, DateTimeOffset Timestamp) : RoundSucceeded(Id, Timestamp); + + public record DomainEvent11(DateTimeOffset Timestamp) : INotification; + public record Sound20Created(long Id, DateTimeOffset Timestamp) : DomainEvent11(Timestamp); + public record Sound20Resulted(long Id, long Win, DateTimeOffset Timestamp) : DomainEvent11(Timestamp); + public record Sound20Succeeded(long Id, DateTimeOffset Timestamp) : DomainEvent11(Timestamp); + public record Sound20SucceededActually(long Id, string Because, DateTimeOffset Timestamp) : Sound20Succeeded(Id, Timestamp); + """ + ); + + await inputCompilation.AssertAndVerify( + Assertions.CompilesWithoutDiagnostics, + result => + { + var model = result.Generator.CompilationModel; + Assert.NotNull(model); + var notifications = model.NotificationMessages.ToList(); + Assert.Equal(5 * 4, notifications.Count); + + Assert.All(notifications.AsEnumerable().Take(4), n => n.Name.Should().EndWith("Actually")); + Assert.All( + notifications.AsEnumerable().Reverse().Take(4), + n => n.Name.Should().StartWith("DomainEvent") + ); + } + ); + } } diff --git a/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering#Mediator.g.verified.cs b/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering#Mediator.g.verified.cs index b290af4..2f39541 100644 --- a/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering#Mediator.g.verified.cs +++ b/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering#Mediator.g.verified.cs @@ -536,9 +536,9 @@ private readonly struct DICache private readonly global::System.IServiceProvider _sp; public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundSucceededActually; - public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundSucceeded; - public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundResulted; public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundCreated; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundResulted; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundSucceeded; public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_DomainEvent; public readonly global::Mediator.ForeachAwaitPublisher InternalNotificationPublisherImpl; @@ -562,18 +562,18 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceededActually is not global::Mediator.INotificationHandler[]); Handlers_For_TestCode_RoundSucceededActually = handlers_For_TestCode_RoundSucceededActually.ToArray(); } - var handlers_For_TestCode_RoundSucceeded = sp.GetServices>(); + var handlers_For_TestCode_RoundCreated = sp.GetServices>(); if (containerMetadata.ServicesUnderlyingTypeIsArray) { - global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceeded is global::Mediator.INotificationHandler[]); - Handlers_For_TestCode_RoundSucceeded = global::System.Runtime.CompilerServices.Unsafe.As[]>( - handlers_For_TestCode_RoundSucceeded + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundCreated is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundCreated = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_RoundCreated ); } else { - global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceeded is not global::Mediator.INotificationHandler[]); - Handlers_For_TestCode_RoundSucceeded = handlers_For_TestCode_RoundSucceeded.ToArray(); + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundCreated is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundCreated = handlers_For_TestCode_RoundCreated.ToArray(); } var handlers_For_TestCode_RoundResulted = sp.GetServices>(); if (containerMetadata.ServicesUnderlyingTypeIsArray) @@ -588,18 +588,18 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundResulted is not global::Mediator.INotificationHandler[]); Handlers_For_TestCode_RoundResulted = handlers_For_TestCode_RoundResulted.ToArray(); } - var handlers_For_TestCode_RoundCreated = sp.GetServices>(); + var handlers_For_TestCode_RoundSucceeded = sp.GetServices>(); if (containerMetadata.ServicesUnderlyingTypeIsArray) { - global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundCreated is global::Mediator.INotificationHandler[]); - Handlers_For_TestCode_RoundCreated = global::System.Runtime.CompilerServices.Unsafe.As[]>( - handlers_For_TestCode_RoundCreated + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceeded is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundSucceeded = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_RoundSucceeded ); } else { - global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundCreated is not global::Mediator.INotificationHandler[]); - Handlers_For_TestCode_RoundCreated = handlers_For_TestCode_RoundCreated.ToArray(); + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceeded is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundSucceeded = handlers_For_TestCode_RoundSucceeded.ToArray(); } var handlers_For_TestCode_DomainEvent = sp.GetServices>(); if (containerMetadata.ServicesUnderlyingTypeIsArray) @@ -834,9 +834,9 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet switch (notification) { case global::TestCode.RoundSucceededActually n: return Publish(n, cancellationToken); - case global::TestCode.RoundSucceeded n: return Publish(n, cancellationToken); - case global::TestCode.RoundResulted n: return Publish(n, cancellationToken); case global::TestCode.RoundCreated n: return Publish(n, cancellationToken); + case global::TestCode.RoundResulted n: return Publish(n, cancellationToken); + case global::TestCode.RoundSucceeded n: return Publish(n, cancellationToken); case global::TestCode.DomainEvent n: return Publish(n, cancellationToken); default: { @@ -876,7 +876,7 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet ); } /// - /// Send a notification of type global::TestCode.RoundSucceeded. + /// Send a notification of type global::TestCode.RoundCreated. /// Throws if message is null. /// Throws if handlers throw exception(s). /// @@ -884,14 +884,14 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet /// Cancellation token /// Awaitable task public global::System.Threading.Tasks.ValueTask Publish( - global::TestCode.RoundSucceeded notification, + global::TestCode.RoundCreated notification, global::System.Threading.CancellationToken cancellationToken = default ) { ThrowIfNull(notification, nameof(notification)); - var handlers = _diCacheLazy.Value.Handlers_For_TestCode_RoundSucceeded; + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_RoundCreated; if (handlers.Length == 0) { @@ -899,7 +899,7 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet } var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; return publisher.Publish( - new global::Mediator.NotificationHandlers(handlers, isArray: true), + new global::Mediator.NotificationHandlers(handlers, isArray: true), notification, cancellationToken ); @@ -934,7 +934,7 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet ); } /// - /// Send a notification of type global::TestCode.RoundCreated. + /// Send a notification of type global::TestCode.RoundSucceeded. /// Throws if message is null. /// Throws if handlers throw exception(s). /// @@ -942,14 +942,14 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet /// Cancellation token /// Awaitable task public global::System.Threading.Tasks.ValueTask Publish( - global::TestCode.RoundCreated notification, + global::TestCode.RoundSucceeded notification, global::System.Threading.CancellationToken cancellationToken = default ) { ThrowIfNull(notification, nameof(notification)); - var handlers = _diCacheLazy.Value.Handlers_For_TestCode_RoundCreated; + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_RoundSucceeded; if (handlers.Length == 0) { @@ -957,7 +957,7 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet } var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; return publisher.Publish( - new global::Mediator.NotificationHandlers(handlers, isArray: true), + new global::Mediator.NotificationHandlers(handlers, isArray: true), notification, cancellationToken ); @@ -1010,9 +1010,9 @@ public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMet switch (notification) { case global::TestCode.RoundSucceededActually n: return Publish(n, cancellationToken); - case global::TestCode.RoundSucceeded n: return Publish(n, cancellationToken); - case global::TestCode.RoundResulted n: return Publish(n, cancellationToken); case global::TestCode.RoundCreated n: return Publish(n, cancellationToken); + case global::TestCode.RoundResulted n: return Publish(n, cancellationToken); + case global::TestCode.RoundSucceeded n: return Publish(n, cancellationToken); case global::TestCode.DomainEvent n: return Publish(n, cancellationToken); default: { diff --git a/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#Mediator.g.verified.cs b/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#Mediator.g.verified.cs new file mode 100644 index 0000000..20d4e09 --- /dev/null +++ b/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#Mediator.g.verified.cs @@ -0,0 +1,1826 @@ +//HintName: Mediator.g.cs +// +// Generated by the Mediator source generator. +// + +#pragma warning disable CS8019 // Unused usings +#pragma warning disable CS8321 // Unused local function +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously + +#nullable enable + +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using System.Linq; + +using SD = global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// DI extensions for Mediator. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + public static class MediatorDependencyInjectionExtensions + { + /// + /// Adds the Mediator implementation and handlers of your application. + /// + public static IServiceCollection AddMediator(this IServiceCollection services) + { + return AddMediator(services, null); + } + + /// + /// Adds the Mediator implementation and handlers of your application, with specified options. + /// + public static IServiceCollection AddMediator(this IServiceCollection services, global::System.Action? options) + { + var opts = new global::Mediator.MediatorOptions(); + if (options != null) + options(opts); + + var configuredViaAttribute = false; + if (opts.ServiceLifetime != global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton && !configuredViaAttribute) + { + var errMsg = "Invalid configuration detected for Mediator. "; + errMsg += "Generated code for 'Singleton' lifetime, but got '" + opts.ServiceLifetime + "' lifetime from options. "; + errMsg += "This means that the source generator hasn't seen the 'AddMediator' method call during compilation. "; + errMsg += "Make sure that the 'AddMediator' method is called from the project that references the Mediator.SourceGenerator package."; + throw new global::System.Exception(errMsg); + } + + + services.Add(new SD(typeof(global::Mediator.Mediator), typeof(global::Mediator.Mediator), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + services.TryAdd(new SD(typeof(global::Mediator.IMediator), sp => sp.GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + services.TryAdd(new SD(typeof(global::Mediator.ISender), sp => sp.GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + services.TryAdd(new SD(typeof(global::Mediator.IPublisher), sp => sp.GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + + + + + + + services.Add(new SD(typeof(global::Mediator.ForeachAwaitPublisher), typeof(global::Mediator.ForeachAwaitPublisher), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + services.TryAdd(new SD(typeof(global::Mediator.INotificationPublisher), sp => sp.GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + + services.Add(new SD(typeof(global::Mediator.IContainerProbe), typeof(global::Mediator.ContainerProbe0), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + services.Add(new SD(typeof(global::Mediator.IContainerProbe), typeof(global::Mediator.ContainerProbe1), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + + services.Add(new SD(typeof(global::Mediator.ContainerMetadata), typeof(global::Mediator.ContainerMetadata), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); + + return services; + + [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static global::System.Func GetRequiredService() where T : notnull => sp => sp.GetRequiredService(); + } + } +} + +namespace Mediator +{ + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class RequestClassHandlerWrapper + where TRequest : class, global::Mediator.IRequest + { + private readonly global::Mediator.MessageHandlerDelegate _rootHandler; + + public RequestClassHandlerWrapper( + global::Mediator.IRequestHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Threading.Tasks.ValueTask Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class RequestStructHandlerWrapper + where TRequest : struct, global::Mediator.IRequest + { + private readonly global::Mediator.MessageHandlerDelegate _rootHandler; + + public RequestStructHandlerWrapper( + global::Mediator.IRequestHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Threading.Tasks.ValueTask Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class StreamRequestClassHandlerWrapper + where TRequest : class, global::Mediator.IStreamRequest + { + private readonly global::Mediator.StreamHandlerDelegate _rootHandler; + + public StreamRequestClassHandlerWrapper( + global::Mediator.IStreamRequestHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Collections.Generic.IAsyncEnumerable Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class StreamRequestStructHandlerWrapper + where TRequest : struct, global::Mediator.IStreamRequest + { + private readonly global::Mediator.StreamHandlerDelegate _rootHandler; + + public StreamRequestStructHandlerWrapper( + global::Mediator.IStreamRequestHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Collections.Generic.IAsyncEnumerable Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class CommandClassHandlerWrapper + where TRequest : class, global::Mediator.ICommand + { + private readonly global::Mediator.MessageHandlerDelegate _rootHandler; + + public CommandClassHandlerWrapper( + global::Mediator.ICommandHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Threading.Tasks.ValueTask Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class CommandStructHandlerWrapper + where TRequest : struct, global::Mediator.ICommand + { + private readonly global::Mediator.MessageHandlerDelegate _rootHandler; + + public CommandStructHandlerWrapper( + global::Mediator.ICommandHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Threading.Tasks.ValueTask Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class StreamCommandClassHandlerWrapper + where TRequest : class, global::Mediator.IStreamCommand + { + private readonly global::Mediator.StreamHandlerDelegate _rootHandler; + + public StreamCommandClassHandlerWrapper( + global::Mediator.IStreamCommandHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Collections.Generic.IAsyncEnumerable Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class StreamCommandStructHandlerWrapper + where TRequest : struct, global::Mediator.IStreamCommand + { + private readonly global::Mediator.StreamHandlerDelegate _rootHandler; + + public StreamCommandStructHandlerWrapper( + global::Mediator.IStreamCommandHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Collections.Generic.IAsyncEnumerable Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class QueryClassHandlerWrapper + where TRequest : class, global::Mediator.IQuery + { + private readonly global::Mediator.MessageHandlerDelegate _rootHandler; + + public QueryClassHandlerWrapper( + global::Mediator.IQueryHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Threading.Tasks.ValueTask Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class QueryStructHandlerWrapper + where TRequest : struct, global::Mediator.IQuery + { + private readonly global::Mediator.MessageHandlerDelegate _rootHandler; + + public QueryStructHandlerWrapper( + global::Mediator.IQueryHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Threading.Tasks.ValueTask Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class StreamQueryClassHandlerWrapper + where TRequest : class, global::Mediator.IStreamQuery + { + private readonly global::Mediator.StreamHandlerDelegate _rootHandler; + + public StreamQueryClassHandlerWrapper( + global::Mediator.IStreamQueryHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Collections.Generic.IAsyncEnumerable Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class StreamQueryStructHandlerWrapper + where TRequest : struct, global::Mediator.IStreamQuery + { + private readonly global::Mediator.StreamHandlerDelegate _rootHandler; + + public StreamQueryStructHandlerWrapper( + global::Mediator.IStreamQueryHandler concreteHandler, + global::System.Collections.Generic.IEnumerable> pipelineBehaviours + ) + { + var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; + + foreach (var pipeline in pipelineBehaviours.Reverse()) + { + var handlerCopy = handler; + var pipelineCopy = pipeline; + handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); + } + + _rootHandler = handler; + } + + public global::System.Collections.Generic.IAsyncEnumerable Handle(TRequest request, global::System.Threading.CancellationToken cancellationToken) => + _rootHandler(request, cancellationToken); + } + + internal interface IContainerProbe { } + internal sealed class ContainerProbe0 : IContainerProbe { } + internal sealed class ContainerProbe1 : IContainerProbe { } + + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + internal sealed class ContainerMetadata + { + public readonly bool ServicesUnderlyingTypeIsArray; + + public ContainerMetadata(global::System.IServiceProvider sp) + { + ServicesUnderlyingTypeIsArray = sp.GetServices() is global::Mediator.IContainerProbe[]; + } + } + + /// + /// Generated code for Mediator implementation. + /// This type is also registered as a DI service. + /// Can be used directly for high performance scenarios. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.Diagnostics.DebuggerStepThroughAttribute] + public sealed partial class Mediator : global::Mediator.IMediator, global::Mediator.ISender, global::Mediator.IPublisher + { + private readonly global::System.IServiceProvider _sp; + private readonly global::Mediator.ContainerMetadata _containerMetadata; + + private FastLazyValue _diCacheLazy; + + /// + /// The lifetime of Mediator-related service registrations in DI container. + /// + public const global::Microsoft.Extensions.DependencyInjection.ServiceLifetime ServiceLifetime = global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton; + + /// + /// The name of the notification publisher service that was configured. + /// + public const string NotificationPublisherName = "ForeachAwaitPublisher"; + + /// + /// Constructor for DI, should not be used by consumer. + /// + public Mediator(global::System.IServiceProvider sp) + { + _sp = sp; + _containerMetadata = sp.GetRequiredService(); + _diCacheLazy = new FastLazyValue(() => new DICache(_sp, _containerMetadata)); + } + + private struct FastLazyValue + where T : struct + { + private const long UNINIT = 0; + private const long INITING = 1; + private const long INITD = 2; + + + + private global::System.Func _generator; + private long _state; + private T _value; + + public T Value + { + [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + get + { + if (_state != INITD) + return ValueSlow; + + return _value; + } + } + + private T ValueSlow + { + [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + var prevState = global::System.Threading.Interlocked.CompareExchange(ref _state, INITING, UNINIT); + switch (prevState) + { + case INITD: + // Someone has already completed init + return _value; + case INITING: + // Wait for someone else to complete + var spinWait = default(global::System.Threading.SpinWait); + while (global::System.Threading.Interlocked.Read(ref _state) < INITD) + spinWait.SpinOnce(); + return _value; + case UNINIT: + _value = _generator(); + global::System.Threading.Interlocked.Exchange(ref _state, INITD); + return _value; + } + + return _value; + } + } + + + public FastLazyValue(global::System.Func generator) + { + _generator = generator; + _state = UNINIT; + _value = default; + } + } + + private readonly struct DICache + { + private readonly global::System.IServiceProvider _sp; + + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Round2SucceededActually; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Sound2SucceededActually; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundSucceededActually; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Sound20SucceededActually; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundResulted; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Round2Created; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Round2Resulted; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Round2Succeeded; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Sound20Succeeded; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Sound2Created; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Sound2Resulted; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Sound2Succeeded; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundCreated; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Sound20Created; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_Sound20Resulted; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_RoundSucceeded; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_DomainEvent2; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_DomainEvent10; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_DomainEvent11; + public readonly global::Mediator.INotificationHandler[] Handlers_For_TestCode_DomainEvent; + + public readonly global::Mediator.ForeachAwaitPublisher InternalNotificationPublisherImpl; + + public DICache(global::System.IServiceProvider sp, global::Mediator.ContainerMetadata containerMetadata) + { + _sp = sp; + + + + var handlers_For_TestCode_Round2SucceededActually = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Round2SucceededActually is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Round2SucceededActually = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Round2SucceededActually + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Round2SucceededActually is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Round2SucceededActually = handlers_For_TestCode_Round2SucceededActually.ToArray(); + } + var handlers_For_TestCode_Sound2SucceededActually = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound2SucceededActually is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound2SucceededActually = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Sound2SucceededActually + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound2SucceededActually is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound2SucceededActually = handlers_For_TestCode_Sound2SucceededActually.ToArray(); + } + var handlers_For_TestCode_RoundSucceededActually = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceededActually is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundSucceededActually = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_RoundSucceededActually + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceededActually is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundSucceededActually = handlers_For_TestCode_RoundSucceededActually.ToArray(); + } + var handlers_For_TestCode_Sound20SucceededActually = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound20SucceededActually is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound20SucceededActually = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Sound20SucceededActually + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound20SucceededActually is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound20SucceededActually = handlers_For_TestCode_Sound20SucceededActually.ToArray(); + } + var handlers_For_TestCode_RoundResulted = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundResulted is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundResulted = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_RoundResulted + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundResulted is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundResulted = handlers_For_TestCode_RoundResulted.ToArray(); + } + var handlers_For_TestCode_Round2Created = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Round2Created is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Round2Created = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Round2Created + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Round2Created is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Round2Created = handlers_For_TestCode_Round2Created.ToArray(); + } + var handlers_For_TestCode_Round2Resulted = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Round2Resulted is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Round2Resulted = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Round2Resulted + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Round2Resulted is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Round2Resulted = handlers_For_TestCode_Round2Resulted.ToArray(); + } + var handlers_For_TestCode_Round2Succeeded = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Round2Succeeded is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Round2Succeeded = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Round2Succeeded + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Round2Succeeded is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Round2Succeeded = handlers_For_TestCode_Round2Succeeded.ToArray(); + } + var handlers_For_TestCode_Sound20Succeeded = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound20Succeeded is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound20Succeeded = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Sound20Succeeded + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound20Succeeded is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound20Succeeded = handlers_For_TestCode_Sound20Succeeded.ToArray(); + } + var handlers_For_TestCode_Sound2Created = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound2Created is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound2Created = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Sound2Created + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound2Created is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound2Created = handlers_For_TestCode_Sound2Created.ToArray(); + } + var handlers_For_TestCode_Sound2Resulted = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound2Resulted is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound2Resulted = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Sound2Resulted + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound2Resulted is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound2Resulted = handlers_For_TestCode_Sound2Resulted.ToArray(); + } + var handlers_For_TestCode_Sound2Succeeded = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound2Succeeded is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound2Succeeded = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Sound2Succeeded + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound2Succeeded is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound2Succeeded = handlers_For_TestCode_Sound2Succeeded.ToArray(); + } + var handlers_For_TestCode_RoundCreated = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundCreated is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundCreated = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_RoundCreated + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundCreated is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundCreated = handlers_For_TestCode_RoundCreated.ToArray(); + } + var handlers_For_TestCode_Sound20Created = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound20Created is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound20Created = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Sound20Created + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound20Created is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound20Created = handlers_For_TestCode_Sound20Created.ToArray(); + } + var handlers_For_TestCode_Sound20Resulted = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound20Resulted is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound20Resulted = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_Sound20Resulted + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_Sound20Resulted is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_Sound20Resulted = handlers_For_TestCode_Sound20Resulted.ToArray(); + } + var handlers_For_TestCode_RoundSucceeded = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceeded is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundSucceeded = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_RoundSucceeded + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_RoundSucceeded is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_RoundSucceeded = handlers_For_TestCode_RoundSucceeded.ToArray(); + } + var handlers_For_TestCode_DomainEvent2 = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_DomainEvent2 is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_DomainEvent2 = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_DomainEvent2 + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_DomainEvent2 is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_DomainEvent2 = handlers_For_TestCode_DomainEvent2.ToArray(); + } + var handlers_For_TestCode_DomainEvent10 = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_DomainEvent10 is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_DomainEvent10 = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_DomainEvent10 + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_DomainEvent10 is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_DomainEvent10 = handlers_For_TestCode_DomainEvent10.ToArray(); + } + var handlers_For_TestCode_DomainEvent11 = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_DomainEvent11 is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_DomainEvent11 = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_DomainEvent11 + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_DomainEvent11 is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_DomainEvent11 = handlers_For_TestCode_DomainEvent11.ToArray(); + } + var handlers_For_TestCode_DomainEvent = sp.GetServices>(); + if (containerMetadata.ServicesUnderlyingTypeIsArray) + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_DomainEvent is global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_DomainEvent = global::System.Runtime.CompilerServices.Unsafe.As[]>( + handlers_For_TestCode_DomainEvent + ); + } + else + { + global::System.Diagnostics.Debug.Assert(handlers_For_TestCode_DomainEvent is not global::Mediator.INotificationHandler[]); + Handlers_For_TestCode_DomainEvent = handlers_For_TestCode_DomainEvent.ToArray(); + } + + + InternalNotificationPublisherImpl = sp.GetRequiredService(); + } + } + + + /// + /// Send request. + /// Throws if message is null. + /// Throws if request does not implement . + /// Throws if no handler is registered. + /// + /// Incoming request + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Send( + global::Mediator.IRequest request, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidRequest(request, nameof(request)); + return default; + } + + /// + /// Send request. + /// Throws if message is null. + /// Throws if no handler is registered. + /// + /// Incoming request + /// Cancellation token + /// Awaitable task + private async global::System.Threading.Tasks.ValueTask SendAsync( + global::Mediator.IRequest request, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidRequest(request, nameof(request)); + return default; + } + + /// + /// Create stream for request. + /// Throws if message is null. + /// Throws if request does not implement . + /// Throws if no handler is registered. + /// + /// Incoming message + /// Cancellation token + /// Async enumerable + public global::System.Collections.Generic.IAsyncEnumerable CreateStream( + global::Mediator.IStreamRequest request, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidStreamRequest(request, nameof(request)); + return default; + } + + /// + /// Send command. + /// Throws if message is null. + /// Throws if command does not implement . + /// Throws if no handler is registered. + /// + /// Incoming command + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Send( + global::Mediator.ICommand command, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidCommand(command, nameof(command)); + return default; + } + + /// + /// Send command. + /// Throws if message is null. + /// Throws if no handler is registered. + /// + /// Incoming command + /// Cancellation token + /// Awaitable task + private async global::System.Threading.Tasks.ValueTask SendAsync( + global::Mediator.ICommand command, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidCommand(command, nameof(command)); + return default; + } + + /// + /// Create stream for command. + /// Throws if message is null. + /// Throws if command does not implement . + /// Throws if no handler is registered. + /// + /// Incoming message + /// Cancellation token + /// Async enumerable + public global::System.Collections.Generic.IAsyncEnumerable CreateStream( + global::Mediator.IStreamCommand command, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidStreamCommand(command, nameof(command)); + return default; + } + + /// + /// Send query. + /// Throws if message is null. + /// Throws if query does not implement . + /// Throws if no handler is registered. + /// + /// Incoming query + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Send( + global::Mediator.IQuery query, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidQuery(query, nameof(query)); + return default; + } + + /// + /// Send query. + /// Throws if message is null. + /// Throws if no handler is registered. + /// + /// Incoming query + /// Cancellation token + /// Awaitable task + private async global::System.Threading.Tasks.ValueTask SendAsync( + global::Mediator.IQuery query, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidQuery(query, nameof(query)); + return default; + } + + /// + /// Create stream for query. + /// Throws if message is null. + /// Throws if query does not implement . + /// Throws if no handler is registered. + /// + /// Incoming message + /// Cancellation token + /// Async enumerable + public global::System.Collections.Generic.IAsyncEnumerable CreateStream( + global::Mediator.IStreamQuery query, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidStreamQuery(query, nameof(query)); + return default; + } + + /// + /// Send message. + /// Throws if message is null. + /// Throws if message does not implement . + /// Throws if no handler is registered. + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Send( + object message, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidMessage(message, nameof(message)); + return default; + } + + /// + /// Create stream. + /// Throws if message is null. + /// Throws if message does not implement . + /// Throws if no handler is registered. + /// + /// Incoming message + /// Cancellation token + /// Async enumerable + public global::System.Collections.Generic.IAsyncEnumerable CreateStream( + object message, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowInvalidStreamMessage(message, nameof(message)); + return default; + } + + /// + /// Publish notification. + /// Throws if message is null. + /// Throws if notification does not implement . + /// Throws if handlers throw exception(s). + /// Drops messages + /// + /// Incoming notification + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + object notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + switch (notification) + { + case global::TestCode.Round2SucceededActually n: return Publish(n, cancellationToken); + case global::TestCode.Sound2SucceededActually n: return Publish(n, cancellationToken); + case global::TestCode.RoundSucceededActually n: return Publish(n, cancellationToken); + case global::TestCode.Sound20SucceededActually n: return Publish(n, cancellationToken); + case global::TestCode.RoundResulted n: return Publish(n, cancellationToken); + case global::TestCode.Round2Created n: return Publish(n, cancellationToken); + case global::TestCode.Round2Resulted n: return Publish(n, cancellationToken); + case global::TestCode.Round2Succeeded n: return Publish(n, cancellationToken); + case global::TestCode.Sound20Succeeded n: return Publish(n, cancellationToken); + case global::TestCode.Sound2Created n: return Publish(n, cancellationToken); + case global::TestCode.Sound2Resulted n: return Publish(n, cancellationToken); + case global::TestCode.Sound2Succeeded n: return Publish(n, cancellationToken); + case global::TestCode.RoundCreated n: return Publish(n, cancellationToken); + case global::TestCode.Sound20Created n: return Publish(n, cancellationToken); + case global::TestCode.Sound20Resulted n: return Publish(n, cancellationToken); + case global::TestCode.RoundSucceeded n: return Publish(n, cancellationToken); + case global::TestCode.DomainEvent2 n: return Publish(n, cancellationToken); + case global::TestCode.DomainEvent10 n: return Publish(n, cancellationToken); + case global::TestCode.DomainEvent11 n: return Publish(n, cancellationToken); + case global::TestCode.DomainEvent n: return Publish(n, cancellationToken); + default: + { + ThrowInvalidNotification(notification, nameof(notification)); + return default; + } + } + } + + /// + /// Send a notification of type global::TestCode.Round2SucceededActually. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Round2SucceededActually notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Round2SucceededActually; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Sound2SucceededActually. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Sound2SucceededActually notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Sound2SucceededActually; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.RoundSucceededActually. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.RoundSucceededActually notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_RoundSucceededActually; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Sound20SucceededActually. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Sound20SucceededActually notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Sound20SucceededActually; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.RoundResulted. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.RoundResulted notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_RoundResulted; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Round2Created. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Round2Created notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Round2Created; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Round2Resulted. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Round2Resulted notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Round2Resulted; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Round2Succeeded. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Round2Succeeded notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Round2Succeeded; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Sound20Succeeded. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Sound20Succeeded notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Sound20Succeeded; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Sound2Created. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Sound2Created notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Sound2Created; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Sound2Resulted. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Sound2Resulted notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Sound2Resulted; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Sound2Succeeded. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Sound2Succeeded notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Sound2Succeeded; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.RoundCreated. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.RoundCreated notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_RoundCreated; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Sound20Created. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Sound20Created notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Sound20Created; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.Sound20Resulted. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.Sound20Resulted notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_Sound20Resulted; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.RoundSucceeded. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.RoundSucceeded notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_RoundSucceeded; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.DomainEvent2. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.DomainEvent2 notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_DomainEvent2; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.DomainEvent10. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.DomainEvent10 notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_DomainEvent10; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.DomainEvent11. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.DomainEvent11 notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_DomainEvent11; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + /// + /// Send a notification of type global::TestCode.DomainEvent. + /// Throws if message is null. + /// Throws if handlers throw exception(s). + /// + /// Incoming message + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + global::TestCode.DomainEvent notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + { + ThrowIfNull(notification, nameof(notification)); + + + var handlers = _diCacheLazy.Value.Handlers_For_TestCode_DomainEvent; + + if (handlers.Length == 0) + { + return default; + } + var publisher = _diCacheLazy.Value.InternalNotificationPublisherImpl; + return publisher.Publish( + new global::Mediator.NotificationHandlers(handlers, isArray: true), + notification, + cancellationToken + ); + } + + /// + /// Publish notification. + /// Throws if message is null. + /// Throws if notification does not implement . + /// Throws if handlers throw exception(s). + /// + /// Incoming notification + /// Cancellation token + /// Awaitable task + public global::System.Threading.Tasks.ValueTask Publish( + TNotification notification, + global::System.Threading.CancellationToken cancellationToken = default + ) + where TNotification : global::Mediator.INotification + { + switch (notification) + { + case global::TestCode.Round2SucceededActually n: return Publish(n, cancellationToken); + case global::TestCode.Sound2SucceededActually n: return Publish(n, cancellationToken); + case global::TestCode.RoundSucceededActually n: return Publish(n, cancellationToken); + case global::TestCode.Sound20SucceededActually n: return Publish(n, cancellationToken); + case global::TestCode.RoundResulted n: return Publish(n, cancellationToken); + case global::TestCode.Round2Created n: return Publish(n, cancellationToken); + case global::TestCode.Round2Resulted n: return Publish(n, cancellationToken); + case global::TestCode.Round2Succeeded n: return Publish(n, cancellationToken); + case global::TestCode.Sound20Succeeded n: return Publish(n, cancellationToken); + case global::TestCode.Sound2Created n: return Publish(n, cancellationToken); + case global::TestCode.Sound2Resulted n: return Publish(n, cancellationToken); + case global::TestCode.Sound2Succeeded n: return Publish(n, cancellationToken); + case global::TestCode.RoundCreated n: return Publish(n, cancellationToken); + case global::TestCode.Sound20Created n: return Publish(n, cancellationToken); + case global::TestCode.Sound20Resulted n: return Publish(n, cancellationToken); + case global::TestCode.RoundSucceeded n: return Publish(n, cancellationToken); + case global::TestCode.DomainEvent2 n: return Publish(n, cancellationToken); + case global::TestCode.DomainEvent10 n: return Publish(n, cancellationToken); + case global::TestCode.DomainEvent11 n: return Publish(n, cancellationToken); + case global::TestCode.DomainEvent n: return Publish(n, cancellationToken); + default: + { + ThrowInvalidNotification(notification, nameof(notification)); + return default; + } + } + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowMissingHandler(object msg) => + throw new global::Mediator.MissingMessageHandlerException(msg); + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidMessage(T? msg, string? paramName = null) + { + if (msg == null) + ThrowArgumentNull(paramName); + else if (!(msg is global::Mediator.IMessage)) + ThrowInvalidMessage(msg); + else + ThrowMissingHandler(msg); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidRequest(T? msg, string? paramName = null) + { + if (msg == null) + ThrowArgumentNull(paramName); + else if (!(msg is global::Mediator.IBaseRequest)) + ThrowInvalidMessage(msg); + else + ThrowMissingHandler(msg); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidCommand(T? msg, string? paramName = null) + { + if (msg == null) + ThrowArgumentNull(paramName); + else if (!(msg is global::Mediator.IBaseCommand)) + ThrowInvalidMessage(msg); + else + ThrowMissingHandler(msg); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidQuery(T? msg, string? paramName = null) + { + if (msg == null) + ThrowArgumentNull(paramName); + else if (!(msg is global::Mediator.IBaseQuery)) + ThrowInvalidMessage(msg); + else + ThrowMissingHandler(msg); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidStreamMessage(T? msg, string? paramName = null) + { + if (msg == null) + ThrowArgumentNull(paramName); + else if (!(msg is global::Mediator.IStreamMessage)) + ThrowInvalidMessage(msg); + else + ThrowMissingHandler(msg); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidStreamRequest(T? msg, string? paramName = null) + { + if (msg == null) + ThrowArgumentNull(paramName); + else if (!(msg is global::Mediator.IBaseStreamRequest)) + ThrowInvalidMessage(msg); + else + ThrowMissingHandler(msg); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidStreamCommand(T? msg, string? paramName = null) + { + if (msg == null) + ThrowArgumentNull(paramName); + else if (!(msg is global::Mediator.IBaseStreamCommand)) + ThrowInvalidMessage(msg); + else + ThrowMissingHandler(msg); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidStreamQuery(T? msg, string? paramName = null) + { + if (msg == null) + ThrowArgumentNull(paramName); + else if (!(msg is global::Mediator.IBaseStreamQuery)) + ThrowInvalidMessage(msg); + else + ThrowMissingHandler(msg); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowArgumentNull(string? paramName) => + throw new global::System.ArgumentNullException(paramName); + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowInvalidMessage(T msg) => + throw new global::Mediator.InvalidMessageException(msg); + + private static void ThrowIfNull(T? argument, string paramName) + { + if (argument == null) + ThrowArgumentNull(paramName); + } + + private static void ThrowInvalidNotification(T? argument, string paramName) + { + if (argument == null) + ThrowArgumentNull(paramName); + else if (!(argument is global::Mediator.INotification)) + ThrowInvalidMessage(argument); + } + + [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] + private static void ThrowAggregateException(global::System.Collections.Generic.List exceptions) => + throw new global::System.AggregateException(exceptions); + + private static void MaybeThrowAggregateException(global::System.Collections.Generic.List? exceptions) + { + if (exceptions != null) + { + ThrowAggregateException(exceptions); + } + } + } +} diff --git a/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#MediatorOptions.g.verified.cs b/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#MediatorOptions.g.verified.cs new file mode 100644 index 0000000..f5dce9a --- /dev/null +++ b/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#MediatorOptions.g.verified.cs @@ -0,0 +1,33 @@ +//HintName: MediatorOptions.g.cs +// +// Generated by the Mediator source generator. +// + +namespace Mediator +{ + /// + /// Provide options for the Mediator source generator. + /// + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + public sealed class MediatorOptions + { + /// + /// The namespace in which the Mediator implementation is generated. + /// By default, the namespace is "Mediator". + /// + public string Namespace { get; set; } = "Mediator"; + + /// + /// The type to use when publishing notifications. + /// By default, the type is . + /// + public global::System.Type NotificationPublisherType { get; set; } = typeof(global::Mediator.ForeachAwaitPublisher); + + /// + /// The default lifetime of the services registered in the DI container by the Mediator source generator. + /// By default, the lifetime is . + /// + public global::Microsoft.Extensions.DependencyInjection.ServiceLifetime ServiceLifetime { get; set; } = + global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton; + } +} diff --git a/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#MediatorOptionsAttribute.g.verified.cs b/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#MediatorOptionsAttribute.g.verified.cs new file mode 100644 index 0000000..f3c6f8c --- /dev/null +++ b/test/Mediator.SourceGenerator.Tests/_snapshots/MessageOrderingTests.Test_Notifications_Ordering_Bigger#MediatorOptionsAttribute.g.verified.cs @@ -0,0 +1,34 @@ +//HintName: MediatorOptionsAttribute.g.cs +// +// Generated by the Mediator source generator. +// + +namespace Mediator +{ + /// + /// Provide options for the Mediator source generator. + /// + [global::System.AttributeUsage(global::System.AttributeTargets.Assembly, AllowMultiple = false)] + [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] + public sealed class MediatorOptionsAttribute : global::System.Attribute + { + /// + /// The namespace in which the Mediator implementation is generated. + /// By default, the namespace is "Mediator". + /// + public string Namespace { get; set; } = "Mediator"; + + /// + /// The type to use when publishing notifications. + /// By default, the type is . + /// + public global::System.Type NotificationPublisherType { get; set; } = typeof(global::Mediator.ForeachAwaitPublisher); + + /// + /// The default lifetime of the services registered in the DI container by the Mediator source generator. + /// By default, the lifetime is . + /// + public global::Microsoft.Extensions.DependencyInjection.ServiceLifetime ServiceLifetime { get; set; } = + global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton; + } +}