diff --git a/.gitignore b/.gitignore index a8a357f328b..b5ee7a08d72 100644 --- a/.gitignore +++ b/.gitignore @@ -328,3 +328,5 @@ packages.lock.json Directory.Build.user.props .generated/ .claude/ + +src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/ diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.g.cs deleted file mode 100644 index d44e27c4f92..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.g.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -#pragma warning disable CS1591 - -namespace Mocha.Mediator.Benchmarks.Messaging; - -partial class ImmediateCommandHandler -{ - public sealed partial class Handler : global::Immediate.Handlers.Shared.IHandler - { - private readonly global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.HandleBehavior _handleBehavior; - - public Handler( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.HandleBehavior handleBehavior - ) - { - var handlerType = typeof(ImmediateCommandHandler); - - _handleBehavior = handleBehavior; - - } - - public async global::System.Threading.Tasks.ValueTask HandleAsync( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.Command request, - global::System.Threading.CancellationToken cancellationToken = default - ) - { - return await _handleBehavior - .HandleAsync(request, cancellationToken) - .ConfigureAwait(false); - } - } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public sealed class HandleBehavior : global::Immediate.Handlers.Shared.Behavior - { - - public HandleBehavior( - ) - { - } - - public override async global::System.Threading.Tasks.ValueTask HandleAsync( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.Command request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return await global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler - .HandleAsync( - request - , cancellationToken - ) - .ConfigureAwait(false); - } - } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public static IServiceCollection AddHandlers( - IServiceCollection services, - ServiceLifetime lifetime = ServiceLifetime.Scoped - ) - { - services.Add(new(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.Handler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.Handler), lifetime)); - services.Add(new(typeof(global::Immediate.Handlers.Shared.IHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.Handler), lifetime)); - services.Add(new(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.HandleBehavior), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.HandleBehavior), lifetime)); - return services; - } -} diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.g.cs deleted file mode 100644 index ee4801c1fa9..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.g.cs +++ /dev/null @@ -1,86 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -#pragma warning disable CS1591 - -namespace Mocha.Mediator.Benchmarks.Messaging; - -partial class ImmediateFullPipelineCommandHandler -{ - public sealed partial class Handler : global::Immediate.Handlers.Shared.IHandler - { - private readonly global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.HandleBehavior _handleBehavior; - private readonly global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelinePostBehavior _immediateFullPipelinePostBehavior; - private readonly global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineMainBehavior _immediateFullPipelineMainBehavior; - private readonly global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelinePreBehavior _immediateFullPipelinePreBehavior; - - public Handler( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.HandleBehavior handleBehavior, - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelinePostBehavior immediateFullPipelinePostBehavior, - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineMainBehavior immediateFullPipelineMainBehavior, - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelinePreBehavior immediateFullPipelinePreBehavior - ) - { - var handlerType = typeof(ImmediateFullPipelineCommandHandler); - - _handleBehavior = handleBehavior; - - _immediateFullPipelinePreBehavior = immediateFullPipelinePreBehavior; - _immediateFullPipelinePreBehavior.HandlerType = handlerType; - - _immediateFullPipelineMainBehavior = immediateFullPipelineMainBehavior; - _immediateFullPipelineMainBehavior.HandlerType = handlerType; - - _immediateFullPipelinePostBehavior = immediateFullPipelinePostBehavior; - _immediateFullPipelinePostBehavior.HandlerType = handlerType; - - _immediateFullPipelinePostBehavior.SetInnerHandler(_handleBehavior); - _immediateFullPipelineMainBehavior.SetInnerHandler(_immediateFullPipelinePostBehavior); - _immediateFullPipelinePreBehavior.SetInnerHandler(_immediateFullPipelineMainBehavior); - } - - public async global::System.Threading.Tasks.ValueTask HandleAsync( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.Command request, - global::System.Threading.CancellationToken cancellationToken = default - ) - { - return await _immediateFullPipelinePreBehavior - .HandleAsync(request, cancellationToken) - .ConfigureAwait(false); - } - } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public sealed class HandleBehavior : global::Immediate.Handlers.Shared.Behavior - { - - public HandleBehavior( - ) - { - } - - public override async global::System.Threading.Tasks.ValueTask HandleAsync( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.Command request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return await global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler - .HandleAsync( - request - , cancellationToken - ) - .ConfigureAwait(false); - } - } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public static IServiceCollection AddHandlers( - IServiceCollection services, - ServiceLifetime lifetime = ServiceLifetime.Scoped - ) - { - services.Add(new(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.Handler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.Handler), lifetime)); - services.Add(new(typeof(global::Immediate.Handlers.Shared.IHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.Handler), lifetime)); - services.Add(new(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.HandleBehavior), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.HandleBehavior), lifetime)); - return services; - } -} diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.g.cs deleted file mode 100644 index 424dacfe6aa..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.g.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -#pragma warning disable CS1591 - -namespace Mocha.Mediator.Benchmarks.Messaging; - -partial class ImmediatePipelineCommandHandler -{ - public sealed partial class Handler : global::Immediate.Handlers.Shared.IHandler - { - private readonly global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.HandleBehavior _handleBehavior; - private readonly global::Mocha.Mediator.Benchmarks.Messaging.ImmediateBenchmarkBehavior _immediateBenchmarkBehavior; - - public Handler( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.HandleBehavior handleBehavior, - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateBenchmarkBehavior immediateBenchmarkBehavior - ) - { - var handlerType = typeof(ImmediatePipelineCommandHandler); - - _handleBehavior = handleBehavior; - - _immediateBenchmarkBehavior = immediateBenchmarkBehavior; - _immediateBenchmarkBehavior.HandlerType = handlerType; - - _immediateBenchmarkBehavior.SetInnerHandler(_handleBehavior); - } - - public async global::System.Threading.Tasks.ValueTask HandleAsync( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.Command request, - global::System.Threading.CancellationToken cancellationToken = default - ) - { - return await _immediateBenchmarkBehavior - .HandleAsync(request, cancellationToken) - .ConfigureAwait(false); - } - } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public sealed class HandleBehavior : global::Immediate.Handlers.Shared.Behavior - { - - public HandleBehavior( - ) - { - } - - public override async global::System.Threading.Tasks.ValueTask HandleAsync( - global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.Command request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return await global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler - .HandleAsync( - request - , cancellationToken - ) - .ConfigureAwait(false); - } - } - - [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] - public static IServiceCollection AddHandlers( - IServiceCollection services, - ServiceLifetime lifetime = ServiceLifetime.Scoped - ) - { - services.Add(new(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.Handler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.Handler), lifetime)); - services.Add(new(typeof(global::Immediate.Handlers.Shared.IHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.Handler), lifetime)); - services.Add(new(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.HandleBehavior), typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.HandleBehavior), lifetime)); - return services; - } -} diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs deleted file mode 100644 index aa172200091..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; - -#pragma warning disable CS1591 - -namespace Mocha.Mediator.Benchmarks; - -public static class HandlerServiceCollectionExtensions -{ - public static IServiceCollection AddMochaMediatorBenchmarksBehaviors( - this IServiceCollection services) - { - services.TryAddTransient(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelinePreBehavior<,>)); - services.TryAddTransient(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineMainBehavior<,>)); - services.TryAddTransient(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelinePostBehavior<,>)); - services.TryAddTransient(typeof(global::Mocha.Mediator.Benchmarks.Messaging.ImmediateBenchmarkBehavior<,>)); - - return services; - } - - public static IServiceCollection AddMochaMediatorBenchmarksHandlers( - this IServiceCollection services, - ServiceLifetime lifetime = ServiceLifetime.Scoped - ) - { - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateFullPipelineCommandHandler.AddHandlers(services, lifetime); - global::Mocha.Mediator.Benchmarks.Messaging.ImmediateCommandHandler.AddHandlers(services, lifetime); - global::Mocha.Mediator.Benchmarks.Messaging.ImmediatePipelineCommandHandler.AddHandlers(services, lifetime); - - return services; - } -} diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/AssemblyReference.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/AssemblyReference.g.cs deleted file mode 100644 index ab2d7cdbc69..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/AssemblyReference.g.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -// Generated by the Mediator source generator. -// - -namespace Mediator -{ - /// - /// Represents an assembly reference. - /// This is used to specify the types or assemblies to scan for Mediator handlers. - /// - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - public sealed class AssemblyReference - { - /// - /// The assembly reference. - /// - public global::System.Reflection.Assembly Assembly { get; } - - private AssemblyReference(global::System.Reflection.Assembly assembly) - { - Assembly = assembly; - } - - /// - /// Creates a new instance of from the specified type. - /// - /// The type - /// A new instance of - public static implicit operator AssemblyReference(global::System.Type type) => new AssemblyReference(type.Assembly); - - /// - /// Creates a new instance of from the specified assembly. - /// - /// The assembly - /// A new instance of - public static implicit operator AssemblyReference(global::System.Reflection.Assembly assembly) => new AssemblyReference(assembly); - } -} diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/Mediator.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/Mediator.g.cs deleted file mode 100644 index 2f4f8ae0958..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/Mediator.g.cs +++ /dev/null @@ -1,1346 +0,0 @@ -// -// 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; - -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 global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.Mediator), typeof(global::Mediator.Mediator), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.TryAdd(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.IMediator), sp => sp.GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.TryAdd(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.ISender), sp => sp.GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.TryAdd(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.IPublisher), sp => sp.GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - - // Register handlers for request messages - services.TryAdd(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommandHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommandHandler), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.IRequestHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommandHandler), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.Internals.RequestHandlerWrapper), typeof(global::Mediator.Internals.RequestHandlerWrapper), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.TryAdd(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommandHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommandHandler), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.IRequestHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommandHandler), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.Internals.RequestHandlerWrapper), typeof(global::Mediator.Internals.RequestHandlerWrapper), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - - // Register handlers and wrappers for notification messages - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.Internals.NotificationHandlerWrapper), typeof(global::Mediator.Internals.NotificationHandlerWrapper), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - - // Register notification handlers - services.TryAdd(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgNotificationHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgNotificationHandler), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.INotificationHandler), GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - - // Register the notification publisher that was configured - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.ForeachAwaitPublisher), typeof(global::Mediator.ForeachAwaitPublisher), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.TryAdd(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.INotificationPublisher), sp => sp.GetRequiredService(), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - - // Register internal components - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.Internals.IContainerProbe), typeof(global::Mediator.Internals.ContainerProbe0), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.Internals.IContainerProbe), typeof(global::Mediator.Internals.ContainerProbe1), global::Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mediator.Internals.ContainerMetadata), typeof(global::Mediator.Internals.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.Internals -{ - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface IMessageHandlerBase - { - global::System.Threading.Tasks.ValueTask Handle( - object request, - global::System.Threading.CancellationToken cancellationToken - ); - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface INotificationHandlerBase - { - global::System.Threading.Tasks.ValueTask Handle( - object notification, - global::System.Threading.CancellationToken cancellationToken - ); - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface IStreamMessageHandlerBase - { - global::System.Collections.Generic.IAsyncEnumerable Handle( - object request, - global::System.Threading.CancellationToken cancellationToken - ); - } - - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface IRequestHandlerBase : IMessageHandlerBase - { - global::System.Threading.Tasks.ValueTask Handle( - global::Mediator.IRequest request, - global::System.Threading.CancellationToken cancellationToken - ); - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.Diagnostics.DebuggerStepThroughAttribute] - internal sealed class RequestHandlerWrapper : IRequestHandlerBase - where TRequest : global::Mediator.IRequest - { - private global::Mediator.MessageHandlerDelegate _rootHandler = null!; - - public RequestHandlerWrapper Init( - global::Mediator.Internals.ContainerMetadata containerMetadata, - global::System.IServiceProvider sp - ) - { - var concreteHandler = sp.GetRequiredService>(); - var pipelineBehaviours = sp.GetServices>(); - var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; - - global::Mediator.IPipelineBehavior[] pipelineBehavioursArray; - if (containerMetadata.ServicesUnderlyingTypeIsArray) - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is global::Mediator.IPipelineBehavior[] - ); - pipelineBehavioursArray = global::System.Runtime.CompilerServices.Unsafe.As[]>( - pipelineBehaviours - ); - } - else - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is not global::Mediator.IPipelineBehavior[] - ); - pipelineBehavioursArray = pipelineBehaviours.ToArray(); - } - - for (int i = pipelineBehavioursArray.Length - 1; i >= 0; i--) - { - var pipeline = pipelineBehavioursArray[i]; - var handlerCopy = handler; - var pipelineCopy = pipeline; - handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); - } - - _rootHandler = handler; - return this; - } - - public global::System.Threading.Tasks.ValueTask Handle( - TRequest request, - global::System.Threading.CancellationToken cancellationToken - ) - { - var handler = _rootHandler; - return handler(request, cancellationToken); - } - - public global::System.Threading.Tasks.ValueTask Handle( - global::Mediator.IRequest request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return Handle((TRequest)request, cancellationToken); - } - - public async global::System.Threading.Tasks.ValueTask Handle( - object request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return await Handle((TRequest)request, cancellationToken); - } - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface IStreamRequestHandlerBase : IStreamMessageHandlerBase - { - global::System.Collections.Generic.IAsyncEnumerable Handle( - global::Mediator.IStreamRequest request, - global::System.Threading.CancellationToken cancellationToken - ); - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.Diagnostics.DebuggerStepThroughAttribute] - internal sealed class StreamRequestHandlerWrapper : IStreamRequestHandlerBase - where TRequest : global::Mediator.IStreamRequest - { - private global::Mediator.StreamHandlerDelegate _rootHandler = null!; - - public StreamRequestHandlerWrapper Init( - global::Mediator.Internals.ContainerMetadata containerMetadata, - global::System.IServiceProvider sp - ) - { - var concreteHandler = sp.GetRequiredService>(); - var pipelineBehaviours = sp.GetServices>(); - var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; - - global::Mediator.IStreamPipelineBehavior[] pipelineBehavioursArray; - if (containerMetadata.ServicesUnderlyingTypeIsArray) - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is global::Mediator.IStreamPipelineBehavior[] - ); - pipelineBehavioursArray = global::System.Runtime.CompilerServices.Unsafe.As[]>( - pipelineBehaviours - ); - } - else - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is not global::Mediator.IStreamPipelineBehavior[] - ); - pipelineBehavioursArray = pipelineBehaviours.ToArray(); - } - - for (int i = pipelineBehavioursArray.Length - 1; i >= 0; i--) - { - var pipeline = pipelineBehavioursArray[i]; - var handlerCopy = handler; - var pipelineCopy = pipeline; - handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); - } - - _rootHandler = handler; - return this; - } - - public global::System.Collections.Generic.IAsyncEnumerable Handle( - TRequest request, - global::System.Threading.CancellationToken cancellationToken - ) - { - var handler = _rootHandler; - return handler(request, cancellationToken); - } - - public global::System.Collections.Generic.IAsyncEnumerable Handle( - global::Mediator.IStreamRequest request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return Handle((TRequest)request, cancellationToken); - } - - public async global::System.Collections.Generic.IAsyncEnumerable Handle( - object request, - [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken - ) - { - await foreach (var el in Handle((TRequest)request, cancellationToken)) - yield return el; - } - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface ICommandHandlerBase : IMessageHandlerBase - { - global::System.Threading.Tasks.ValueTask Handle( - global::Mediator.ICommand request, - global::System.Threading.CancellationToken cancellationToken - ); - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.Diagnostics.DebuggerStepThroughAttribute] - internal sealed class CommandHandlerWrapper : ICommandHandlerBase - where TRequest : global::Mediator.ICommand - { - private global::Mediator.MessageHandlerDelegate _rootHandler = null!; - - public CommandHandlerWrapper Init( - global::Mediator.Internals.ContainerMetadata containerMetadata, - global::System.IServiceProvider sp - ) - { - var concreteHandler = sp.GetRequiredService>(); - var pipelineBehaviours = sp.GetServices>(); - var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; - - global::Mediator.IPipelineBehavior[] pipelineBehavioursArray; - if (containerMetadata.ServicesUnderlyingTypeIsArray) - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is global::Mediator.IPipelineBehavior[] - ); - pipelineBehavioursArray = global::System.Runtime.CompilerServices.Unsafe.As[]>( - pipelineBehaviours - ); - } - else - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is not global::Mediator.IPipelineBehavior[] - ); - pipelineBehavioursArray = pipelineBehaviours.ToArray(); - } - - for (int i = pipelineBehavioursArray.Length - 1; i >= 0; i--) - { - var pipeline = pipelineBehavioursArray[i]; - var handlerCopy = handler; - var pipelineCopy = pipeline; - handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); - } - - _rootHandler = handler; - return this; - } - - public global::System.Threading.Tasks.ValueTask Handle( - TRequest request, - global::System.Threading.CancellationToken cancellationToken - ) - { - var handler = _rootHandler; - return handler(request, cancellationToken); - } - - public global::System.Threading.Tasks.ValueTask Handle( - global::Mediator.ICommand request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return Handle((TRequest)request, cancellationToken); - } - - public async global::System.Threading.Tasks.ValueTask Handle( - object request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return await Handle((TRequest)request, cancellationToken); - } - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface IStreamCommandHandlerBase : IStreamMessageHandlerBase - { - global::System.Collections.Generic.IAsyncEnumerable Handle( - global::Mediator.IStreamCommand request, - global::System.Threading.CancellationToken cancellationToken - ); - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.Diagnostics.DebuggerStepThroughAttribute] - internal sealed class StreamCommandHandlerWrapper : IStreamCommandHandlerBase - where TRequest : global::Mediator.IStreamCommand - { - private global::Mediator.StreamHandlerDelegate _rootHandler = null!; - - public StreamCommandHandlerWrapper Init( - global::Mediator.Internals.ContainerMetadata containerMetadata, - global::System.IServiceProvider sp - ) - { - var concreteHandler = sp.GetRequiredService>(); - var pipelineBehaviours = sp.GetServices>(); - var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; - - global::Mediator.IStreamPipelineBehavior[] pipelineBehavioursArray; - if (containerMetadata.ServicesUnderlyingTypeIsArray) - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is global::Mediator.IStreamPipelineBehavior[] - ); - pipelineBehavioursArray = global::System.Runtime.CompilerServices.Unsafe.As[]>( - pipelineBehaviours - ); - } - else - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is not global::Mediator.IStreamPipelineBehavior[] - ); - pipelineBehavioursArray = pipelineBehaviours.ToArray(); - } - - for (int i = pipelineBehavioursArray.Length - 1; i >= 0; i--) - { - var pipeline = pipelineBehavioursArray[i]; - var handlerCopy = handler; - var pipelineCopy = pipeline; - handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); - } - - _rootHandler = handler; - return this; - } - - public global::System.Collections.Generic.IAsyncEnumerable Handle( - TRequest request, - global::System.Threading.CancellationToken cancellationToken - ) - { - var handler = _rootHandler; - return handler(request, cancellationToken); - } - - public global::System.Collections.Generic.IAsyncEnumerable Handle( - global::Mediator.IStreamCommand request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return Handle((TRequest)request, cancellationToken); - } - - public async global::System.Collections.Generic.IAsyncEnumerable Handle( - object request, - [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken - ) - { - await foreach (var el in Handle((TRequest)request, cancellationToken)) - yield return el; - } - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface IQueryHandlerBase : IMessageHandlerBase - { - global::System.Threading.Tasks.ValueTask Handle( - global::Mediator.IQuery request, - global::System.Threading.CancellationToken cancellationToken - ); - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.Diagnostics.DebuggerStepThroughAttribute] - internal sealed class QueryHandlerWrapper : IQueryHandlerBase - where TRequest : global::Mediator.IQuery - { - private global::Mediator.MessageHandlerDelegate _rootHandler = null!; - - public QueryHandlerWrapper Init( - global::Mediator.Internals.ContainerMetadata containerMetadata, - global::System.IServiceProvider sp - ) - { - var concreteHandler = sp.GetRequiredService>(); - var pipelineBehaviours = sp.GetServices>(); - var handler = (global::Mediator.MessageHandlerDelegate)concreteHandler.Handle; - - global::Mediator.IPipelineBehavior[] pipelineBehavioursArray; - if (containerMetadata.ServicesUnderlyingTypeIsArray) - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is global::Mediator.IPipelineBehavior[] - ); - pipelineBehavioursArray = global::System.Runtime.CompilerServices.Unsafe.As[]>( - pipelineBehaviours - ); - } - else - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is not global::Mediator.IPipelineBehavior[] - ); - pipelineBehavioursArray = pipelineBehaviours.ToArray(); - } - - for (int i = pipelineBehavioursArray.Length - 1; i >= 0; i--) - { - var pipeline = pipelineBehavioursArray[i]; - var handlerCopy = handler; - var pipelineCopy = pipeline; - handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); - } - - _rootHandler = handler; - return this; - } - - public global::System.Threading.Tasks.ValueTask Handle( - TRequest request, - global::System.Threading.CancellationToken cancellationToken - ) - { - var handler = _rootHandler; - return handler(request, cancellationToken); - } - - public global::System.Threading.Tasks.ValueTask Handle( - global::Mediator.IQuery request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return Handle((TRequest)request, cancellationToken); - } - - public async global::System.Threading.Tasks.ValueTask Handle( - object request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return await Handle((TRequest)request, cancellationToken); - } - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - internal interface IStreamQueryHandlerBase : IStreamMessageHandlerBase - { - global::System.Collections.Generic.IAsyncEnumerable Handle( - global::Mediator.IStreamQuery request, - global::System.Threading.CancellationToken cancellationToken - ); - } - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.Diagnostics.DebuggerStepThroughAttribute] - internal sealed class StreamQueryHandlerWrapper : IStreamQueryHandlerBase - where TRequest : global::Mediator.IStreamQuery - { - private global::Mediator.StreamHandlerDelegate _rootHandler = null!; - - public StreamQueryHandlerWrapper Init( - global::Mediator.Internals.ContainerMetadata containerMetadata, - global::System.IServiceProvider sp - ) - { - var concreteHandler = sp.GetRequiredService>(); - var pipelineBehaviours = sp.GetServices>(); - var handler = (global::Mediator.StreamHandlerDelegate)concreteHandler.Handle; - - global::Mediator.IStreamPipelineBehavior[] pipelineBehavioursArray; - if (containerMetadata.ServicesUnderlyingTypeIsArray) - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is global::Mediator.IStreamPipelineBehavior[] - ); - pipelineBehavioursArray = global::System.Runtime.CompilerServices.Unsafe.As[]>( - pipelineBehaviours - ); - } - else - { - global::System.Diagnostics.Debug.Assert( - pipelineBehaviours is not global::Mediator.IStreamPipelineBehavior[] - ); - pipelineBehavioursArray = pipelineBehaviours.ToArray(); - } - - for (int i = pipelineBehavioursArray.Length - 1; i >= 0; i--) - { - var pipeline = pipelineBehavioursArray[i]; - var handlerCopy = handler; - var pipelineCopy = pipeline; - handler = (TRequest message, System.Threading.CancellationToken cancellationToken) => pipelineCopy.Handle(message, handlerCopy, cancellationToken); - } - - _rootHandler = handler; - return this; - } - - public global::System.Collections.Generic.IAsyncEnumerable Handle( - TRequest request, - global::System.Threading.CancellationToken cancellationToken - ) - { - var handler = _rootHandler; - return handler(request, cancellationToken); - } - - public global::System.Collections.Generic.IAsyncEnumerable Handle( - global::Mediator.IStreamQuery request, - global::System.Threading.CancellationToken cancellationToken - ) - { - return Handle((TRequest)request, cancellationToken); - } - - public async global::System.Collections.Generic.IAsyncEnumerable Handle( - object request, - [global::System.Runtime.CompilerServices.EnumeratorCancellation] global::System.Threading.CancellationToken cancellationToken - ) - { - await foreach (var el in Handle((TRequest)request, cancellationToken)) - yield return el; - } - } - - [global::System.CodeDom.Compiler.GeneratedCode("Mediator.SourceGenerator", "3.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.Diagnostics.DebuggerStepThroughAttribute] - internal sealed class NotificationHandlerWrapper : INotificationHandlerBase - where TNotification : global::Mediator.INotification - { - private global::Mediator.ForeachAwaitPublisher _publisher = null!; - private global::Mediator.INotificationHandler[] _handlers = null!; - - public NotificationHandlerWrapper Init( - global::Mediator.Internals.ContainerMetadata containerMetadata, - global::System.IServiceProvider sp - ) - { - _publisher = containerMetadata.NotificationPublisher; - var handlers = sp.GetServices>(); - if (containerMetadata.ServicesUnderlyingTypeIsArray) - { - global::System.Diagnostics.Debug.Assert( - handlers is global::Mediator.INotificationHandler[], - $"Unexpected type: {handlers.GetType()}" - ); - _handlers = global::System.Runtime.CompilerServices.Unsafe.As[]>( - handlers - ); - } - else - { - global::System.Diagnostics.Debug.Assert( - handlers is not global::Mediator.INotificationHandler[], - $"Unexpected type: {handlers.GetType()}" - ); - _handlers = handlers.ToArray(); - } - return this; - } - - public global::System.Threading.Tasks.ValueTask Handle( - TNotification notification, - global::System.Threading.CancellationToken cancellationToken - ) - { - var handlers = _handlers; - if (handlers.Length == 0) - { - return default; - } - return _publisher.Publish( - new global::Mediator.NotificationHandlers(handlers, isArray: true), - notification, - cancellationToken - ); - } - - public global::System.Threading.Tasks.ValueTask Handle( - object notification, - global::System.Threading.CancellationToken cancellationToken - ) - { - return Handle((TNotification)notification, 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 readonly global::System.Collections.Frozen.FrozenDictionary RequestHandlerWrappers; - public readonly global::System.Collections.Frozen.FrozenDictionary CommandHandlerWrappers; - public readonly global::System.Collections.Frozen.FrozenDictionary QueryHandlerWrappers; - - public readonly global::System.Collections.Frozen.FrozenDictionary StreamRequestHandlerWrappers; - public readonly global::System.Collections.Frozen.FrozenDictionary StreamCommandHandlerWrappers; - public readonly global::System.Collections.Frozen.FrozenDictionary StreamQueryHandlerWrappers; - - public readonly global::System.Collections.Frozen.FrozenDictionary NotificationHandlerWrappers; - - public readonly global::Mediator.Internals.RequestHandlerWrapper Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_FullPipelineMediatorSgCommand; - public readonly global::Mediator.Internals.RequestHandlerWrapper Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_MediatorSgCommand; - - public readonly global::Mediator.Internals.NotificationHandlerWrapper Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_MediatorSgNotification; - - public readonly global::Mediator.ForeachAwaitPublisher NotificationPublisher; - - public ContainerMetadata(global::System.IServiceProvider sp) - { - ServicesUnderlyingTypeIsArray = sp.GetServices() is global::Mediator.Internals.IContainerProbe[]; - - NotificationPublisher = sp.GetRequiredService(); - - var requestHandlerTypes = new global::System.Collections.Generic.Dictionary(2); - var commandHandlerTypes = new global::System.Collections.Generic.Dictionary(0); - var queryHandlerTypes = new global::System.Collections.Generic.Dictionary(0); - requestHandlerTypes.Add(typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommand), sp.GetRequiredService>().Init(this, sp)); - requestHandlerTypes.Add(typeof(global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommand), sp.GetRequiredService>().Init(this, sp)); - RequestHandlerWrappers = global::System.Collections.Frozen.FrozenDictionary.ToFrozenDictionary(requestHandlerTypes); - CommandHandlerWrappers = global::System.Collections.Frozen.FrozenDictionary.ToFrozenDictionary(commandHandlerTypes); - QueryHandlerWrappers = global::System.Collections.Frozen.FrozenDictionary.ToFrozenDictionary(queryHandlerTypes); - - var streamRequestHandlerTypes = new global::System.Collections.Generic.Dictionary(0); - var streamCommandHandlerTypes = new global::System.Collections.Generic.Dictionary(0); - var streamQueryHandlerTypes = new global::System.Collections.Generic.Dictionary(0); - StreamRequestHandlerWrappers = global::System.Collections.Frozen.FrozenDictionary.ToFrozenDictionary(streamRequestHandlerTypes); - StreamCommandHandlerWrappers = global::System.Collections.Frozen.FrozenDictionary.ToFrozenDictionary(streamCommandHandlerTypes); - StreamQueryHandlerWrappers = global::System.Collections.Frozen.FrozenDictionary.ToFrozenDictionary(streamQueryHandlerTypes); - - var notificationHandlerTypes = new global::System.Collections.Generic.Dictionary(1); - notificationHandlerTypes.Add(typeof(global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgNotification), sp.GetRequiredService>().Init(this, sp)); - NotificationHandlerWrappers = global::System.Collections.Frozen.FrozenDictionary.ToFrozenDictionary(notificationHandlerTypes); - - Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_FullPipelineMediatorSgCommand = sp.GetRequiredService>().Init(this, sp); - Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_MediatorSgCommand = sp.GetRequiredService>().Init(this, sp); - - Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_MediatorSgNotification = sp.GetRequiredService>().Init(this, sp); - } - } -} - -namespace Mediator -{ - /// - /// 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 - { - internal readonly global::System.IServiceProvider Services; - private FastLazyValue _containerMetadata; - private global::Mediator.ForeachAwaitPublisher? _notificationPublisher; - internal global::Mediator.ForeachAwaitPublisher NotificationPublisher - { - [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - get - { - if (_notificationPublisher == null) - _notificationPublisher = _containerMetadata.Value.NotificationPublisher; - return _notificationPublisher!; - } - } - private bool? _servicesUnderlyingTypeIsArray; - internal bool ServicesUnderlyingTypeIsArray - { - [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - get - { - if (_servicesUnderlyingTypeIsArray == null) - _servicesUnderlyingTypeIsArray = _containerMetadata.Value.ServicesUnderlyingTypeIsArray; - return _servicesUnderlyingTypeIsArray!.Value; - } - } - - /// - /// 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"; - - /// - /// The total number of Mediator messages that were discovered. - /// - public const int TotalMessages = 3; - - /// - /// Constructor for DI, should not be used by consumer. - /// - public Mediator(global::System.IServiceProvider sp) - { - Services = sp; - _containerMetadata = new FastLazyValue( - self => self.Services.GetRequiredService(), - this - ); - } - - private struct FastLazyValue - { - 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; - private TArg _arg; - - 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(_arg); - global::System.Threading.Interlocked.Exchange(ref _state, INITD); - return _value; - } - - return _value; - } - } - - public FastLazyValue(global::System.Func generator, TArg arg) - { - _generator = generator; - _state = UNINIT; - _value = default!; - _arg = arg; - } - } - - - - /// - /// Send a request of type global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommand. - /// Throws if request is null. - /// - /// Incoming request - /// Cancellation token - /// Awaitable task - public global::System.Threading.Tasks.ValueTask Send( - global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommand request, - global::System.Threading.CancellationToken cancellationToken = default - ) - { - ThrowIfNull(request, nameof(request)); - return _containerMetadata.Value.Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_FullPipelineMediatorSgCommand.Handle(request, cancellationToken); - } - - /// - /// Send a request of type global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommand. - /// Throws if request is null. - /// - /// Incoming request - /// Cancellation token - /// Awaitable task - public global::System.Threading.Tasks.ValueTask Send( - global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommand request, - global::System.Threading.CancellationToken cancellationToken = default - ) - { - ThrowIfNull(request, nameof(request)); - return _containerMetadata.Value.Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_MediatorSgCommand.Handle(request, cancellationToken); - } - - /// - /// 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 - ) - { - switch (request) - { - case global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommand r: - { - if (typeof(TResponse) == typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkResponse)) - { - var task = Send(r, cancellationToken); - return global::System.Runtime.CompilerServices.Unsafe.As, global::System.Threading.Tasks.ValueTask>(ref task); - } - return SendAsync(request, cancellationToken); - } - case global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommand r: - { - if (typeof(TResponse) == typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkResponse)) - { - var task = Send(r, cancellationToken); - return global::System.Runtime.CompilerServices.Unsafe.As, global::System.Threading.Tasks.ValueTask>(ref task); - } - return SendAsync(request, cancellationToken); - } - default: - { - ThrowInvalidRequest(request, nameof(request)); - return default; - } - } - } - - private async global::System.Threading.Tasks.ValueTask SendAsync( - global::Mediator.IRequest request, - global::System.Threading.CancellationToken cancellationToken = default - ) - { - switch (request) - { - case global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommand r: - { - var response = await Send(r, cancellationToken); - return global::System.Runtime.CompilerServices.Unsafe.As(ref response); - } - case global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommand r: - { - var response = await Send(r, cancellationToken); - return global::System.Runtime.CompilerServices.Unsafe.As(ref response); - } - 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; - } - - 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; - } - - 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 async global::System.Threading.Tasks.ValueTask Send( - object message, - global::System.Threading.CancellationToken cancellationToken = default - ) - { - switch (message) - { - case global::Mediator.IBaseRequest request: - switch (request) - { - case global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineMediatorSgCommand r: return await Send(r, cancellationToken); - case global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgCommand r: return await Send(r, cancellationToken); - default: - { - ThrowInvalidRequest(request, nameof(request)); - return default; - } - } - case global::Mediator.IBaseCommand command: - switch (command) - { - default: - { - ThrowInvalidCommand(command, nameof(command)); - return default; - } - } - case global::Mediator.IBaseQuery query: - switch (query) - { - default: - { - ThrowInvalidQuery(query, nameof(query)); - return default; - } - } - 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::Mocha.Mediator.Benchmarks.Messaging.MediatorSgNotification n: return Publish(n, cancellationToken); - default: - { - ThrowInvalidNotification(notification, nameof(notification)); - return default; - } - } - } - - /// - /// Send a notification of type global::Mocha.Mediator.Benchmarks.Messaging.MediatorSgNotification. - /// 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::Mocha.Mediator.Benchmarks.Messaging.MediatorSgNotification notification, - global::System.Threading.CancellationToken cancellationToken = default - ) - { - ThrowIfNull(notification, nameof(notification)); - - return _containerMetadata.Value.Wrapper_For_Mocha_Mediator_Benchmarks_Messaging_MediatorSgNotification.Handle(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::Mocha.Mediator.Benchmarks.Messaging.MediatorSgNotification n: return Publish(n, cancellationToken); - default: - { - ThrowInvalidNotification(notification, nameof(notification)); - return default; - } - } - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - private static void ThrowMissingHandler(object msg) => - throw new global::Mediator.MissingMessageHandlerException(msg); - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - private static void ThrowArgumentNull(string? paramName) => - throw new global::System.ArgumentNullException(paramName); - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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); - } - -#if NETSTANDARD2_1_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] -#endif - 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/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/MediatorOptions.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/MediatorOptions.g.cs deleted file mode 100644 index 309c180ee53..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/MediatorOptions.g.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -// 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"; - - /// - /// Wether or not generated types should be internal (they are public by default). - /// - public bool GenerateTypesAsInternal { get; set; } = false; - - /// - /// 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; - - /// - /// The collection of assemblies to scan for Mediator handlers. - /// By default, the collection is empty, in which case the source generator will scan all assemblies through references from the source generated project. - /// - public global::System.Collections.Generic.IReadOnlyList Assemblies { get; set; } = new global::Mediator.AssemblyReference[0]; - - /// - /// The collection of types of pipeline behaviors to register in DI. - /// When the type is an unconstructed generic type, the source generator will register all the constructed types of the generic type (open generics that is supported during AoT). - /// - public global::System.Collections.Generic.IReadOnlyList PipelineBehaviors { get; set; } = new global::System.Type[0]; - - /// - /// The collection of types of streaming pipeline behaviors to register in DI. - /// When the type is an unconstructed generic type, the source generator will register all the constructed types of the generic type (open generics that is supported during AoT). - /// - public global::System.Collections.Generic.IReadOnlyList StreamPipelineBehaviors { get; set; } = new global::System.Type[0]; - } -} diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/MediatorOptionsAttribute.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/MediatorOptionsAttribute.g.cs deleted file mode 100644 index 8ecee2a6d3c..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.SourceGenerator/Mediator.SourceGenerator.IncrementalMediatorGenerator/MediatorOptionsAttribute.g.cs +++ /dev/null @@ -1,33 +0,0 @@ -// -// 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; - } -} diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.Switch.SourceGenerator/Mediator.Switch.SourceGenerator.SwitchMediatorSourceGenerator/BenchmarkSwitchMediator.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.Switch.SourceGenerator/Mediator.Switch.SourceGenerator.SwitchMediatorSourceGenerator/BenchmarkSwitchMediator.g.cs deleted file mode 100644 index b0d115d06ea..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mediator.Switch.SourceGenerator/Mediator.Switch.SourceGenerator.SwitchMediatorSourceGenerator/BenchmarkSwitchMediator.g.cs +++ /dev/null @@ -1,243 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by SwitchMediator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -#nullable enable - -using System; -using System.Linq; -using System.Collections.Generic; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; - -#if NET8_0_OR_GREATER -using System.Collections.Frozen; -#endif - -namespace Mocha.Mediator.Benchmarks.Messaging; - -#pragma warning disable CS1998 - -public partial class BenchmarkSwitchMediator : global::Mediator.Switch.IMediator, global::Mediator.Switch.IValueMediator -{ - #region Fields - - private global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommandHandler? _mocha_Mediator_Benchmarks_Messaging_FullPipelineSwitchMediatorCommandHandler; - private global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommandHandler? _mocha_Mediator_Benchmarks_Messaging_SwitchMediatorCommandHandler; - private global::System.Collections.Generic.IEnumerable>? _mocha_Mediator_Benchmarks_Messaging_SwitchMediatorNotification__ValueHandlers; - - private readonly global::Mediator.Switch.ISwitchMediatorServiceProvider _svc; - - #endregion - - #region Constructor - - public BenchmarkSwitchMediator(global::Mediator.Switch.ISwitchMediatorServiceProvider serviceProvider) - { - _svc = serviceProvider; - } - - #endregion - - public static (global::System.Collections.Generic.IReadOnlyList RequestHandlerTypes, global::System.Collections.Generic.IReadOnlyList<(global::System.Type NotificationType, global::System.Collections.Generic.IReadOnlyList HandlerTypes)> NotificationTypes, global::System.Collections.Generic.IReadOnlyList PipelineBehaviorTypes) KnownTypes - { - get { return (SwitchMediatorKnownTypes.RequestHandlerTypes, SwitchMediatorKnownTypes.NotificationTypes, SwitchMediatorKnownTypes.PipelineBehaviorTypes); } - } - - public global::System.Threading.Tasks.Task Send(global::Mediator.Switch.IRequest request, global::System.Threading.CancellationToken cancellationToken = default) - { - if (TaskSendSwitchCase.Cases.TryGetValue(request.GetType(), out var handle)) - { - return global::System.Runtime.CompilerServices.Unsafe.As, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task>>(handle)(this, request, cancellationToken); - } - - throw new global::System.ArgumentException($"No handler for {request.GetType().Name}"); - } - - private static class TaskSendSwitchCase - { - public static readonly global::System.Collections.Generic.IDictionary Cases = new (global::System.Type, object)[] - { - ( // case Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommand: - typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommand), (global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task>) ((instance, request, cancellationToken) => - instance.Handle_Mocha_Mediator_Benchmarks_Messaging_FullPipelineSwitchMediatorCommand( - (global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommand) request, cancellationToken).AsTask()) - ), - ( // case Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommand: - typeof(global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommand), (global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task>) ((instance, request, cancellationToken) => - instance.Handle_Mocha_Mediator_Benchmarks_Messaging_SwitchMediatorCommand( - (global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommand) request, cancellationToken).AsTask()) - ) - } -#if NET8_0_OR_GREATER - .ToFrozenDictionary -#else - .ToDictionary -#endif - (t => t.Item1, t => t.Item2); - } - - global::System.Threading.Tasks.ValueTask global::Mediator.Switch.IValueSender.Send(global::Mediator.Switch.IRequest request, global::System.Threading.CancellationToken cancellationToken) - { - if (ValueSendSwitchCase.Cases.TryGetValue(request.GetType(), out var handle)) - { - return global::System.Runtime.CompilerServices.Unsafe.As, global::System.Threading.CancellationToken, global::System.Threading.Tasks.ValueTask>>(handle)(this, request, cancellationToken); - } - - throw new global::System.ArgumentException($"No handler for {request.GetType().Name}"); - } - - private static class ValueSendSwitchCase - { - public static readonly global::System.Collections.Generic.IDictionary Cases = new (global::System.Type, object)[] - { - ( // case Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommand: - typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommand), (global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.ValueTask>) ((instance, request, cancellationToken) => - instance.Handle_Mocha_Mediator_Benchmarks_Messaging_FullPipelineSwitchMediatorCommand( - (global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommand) request, cancellationToken)) - ), - ( // case Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommand: - typeof(global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommand), (global::System.Func, global::System.Threading.CancellationToken, global::System.Threading.Tasks.ValueTask>) ((instance, request, cancellationToken) => - instance.Handle_Mocha_Mediator_Benchmarks_Messaging_SwitchMediatorCommand( - (global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommand) request, cancellationToken)) - ) - } -#if NET8_0_OR_GREATER - .ToFrozenDictionary -#else - .ToDictionary -#endif - (t => t.Item1, t => t.Item2); - } - - public global::System.Threading.Tasks.Task Publish(global::Mediator.Switch.INotification notification, global::System.Threading.CancellationToken cancellationToken = default) - { - if (TaskPublishSwitchCase.Cases.TryGetValue(notification.GetType(), out var handle)) - { - return handle(this, notification, cancellationToken); - } - - if (ValuePublishSwitchCase.Cases.TryGetValue(notification.GetType(), out var valueHandle)) - { - return valueHandle(this, notification, cancellationToken).AsTask(); - } - - return global::System.Threading.Tasks.Task.CompletedTask; - } - - private static class TaskPublishSwitchCase - { - public static readonly global::System.Collections.Generic.IDictionary> Cases = new (global::System.Type, global::System.Func)[] - { - - } -#if NET8_0_OR_GREATER - .ToFrozenDictionary -#else - .ToDictionary -#endif - (t => t.Item1, t => t.Item2); - } - - global::System.Threading.Tasks.ValueTask global::Mediator.Switch.IValuePublisher.Publish(global::Mediator.Switch.INotification notification, global::System.Threading.CancellationToken cancellationToken) - { - if (ValuePublishSwitchCase.Cases.TryGetValue(notification.GetType(), out var handle)) - { - return handle(this, notification, cancellationToken); - } - - if (TaskPublishSwitchCase.Cases.TryGetValue(notification.GetType(), out var taskHandle)) - { - return new global::System.Threading.Tasks.ValueTask(taskHandle(this, notification, cancellationToken)); - } - - return global::System.Threading.Tasks.ValueTask.CompletedTask; - } - - private static class ValuePublishSwitchCase - { - public static readonly global::System.Collections.Generic.IDictionary> Cases = new (global::System.Type, global::System.Func)[] - { - ( // case Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorNotification: - typeof(global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorNotification), async (instance, notification, cancellationToken) => - { - var handlers = instance.Get(ref instance._mocha_Mediator_Benchmarks_Messaging_SwitchMediatorNotification__ValueHandlers); - - var typedNotification = (global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorNotification) notification; - - foreach (var handler in handlers) - { - await - /* Notification Handler */ handler.Handle(typedNotification, cancellationToken); - } - } - ) - } -#if NET8_0_OR_GREATER - .ToFrozenDictionary -#else - .ToDictionary -#endif - (t => t.Item1, t => t.Item2); - } - - private global::System.Threading.Tasks.ValueTask Handle_Mocha_Mediator_Benchmarks_Messaging_FullPipelineSwitchMediatorCommand( - global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommand request, - global::System.Threading.CancellationToken cancellationToken) - { - - var mocha_Mediator_Benchmarks_Messaging_FullPipelineSwitchMediatorCommandHandler = Get(ref _mocha_Mediator_Benchmarks_Messaging_FullPipelineSwitchMediatorCommandHandler); - - return - /* Request Handler */ mocha_Mediator_Benchmarks_Messaging_FullPipelineSwitchMediatorCommandHandler.Handle(request, cancellationToken); - } - - private global::System.Threading.Tasks.ValueTask Handle_Mocha_Mediator_Benchmarks_Messaging_SwitchMediatorCommand( - global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommand request, - global::System.Threading.CancellationToken cancellationToken) - { - - var mocha_Mediator_Benchmarks_Messaging_SwitchMediatorCommandHandler = Get(ref _mocha_Mediator_Benchmarks_Messaging_SwitchMediatorCommandHandler); - - return - /* Request Handler */ mocha_Mediator_Benchmarks_Messaging_SwitchMediatorCommandHandler.Handle(request, cancellationToken); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [DebuggerStepThrough] - private T Get(ref T? field) where T : notnull - { - return field ?? (field = _svc.Get()); - } - - /// - /// Provides lists of SwitchMediator component implementation types. - /// - public static class SwitchMediatorKnownTypes - { - public static readonly global::System.Collections.Generic.IReadOnlyList RequestHandlerTypes = - new global::System.Type[] { - typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineSwitchMediatorCommandHandler), - typeof(global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorCommandHandler) - }.AsReadOnly(); - - public static readonly global::System.Collections.Generic.IReadOnlyList<(global::System.Type NotificationType, global::System.Collections.Generic.IReadOnlyList HandlerTypes)> NotificationTypes = - new (global::System.Type NotificationType, global::System.Collections.Generic.IReadOnlyList HandlerTypes)[] { - (typeof(global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorNotification), new global::System.Type[] { - typeof(global::Mocha.Mediator.Benchmarks.Messaging.SwitchMediatorNotificationHandler) - }) - }.AsReadOnly(); - - public static readonly global::System.Collections.Generic.IReadOnlyList PipelineBehaviorTypes = - new global::System.Type[] { - - }.AsReadOnly(); - } -} \ No newline at end of file diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mocha.Analyzers/Mocha.Analyzers.MediatorGenerator/BenchmarksMediatorBuilderExtensions._RXvJz6gQPQLNfJu4g_tRw.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mocha.Analyzers/Mocha.Analyzers.MediatorGenerator/BenchmarksMediatorBuilderExtensions._RXvJz6gQPQLNfJu4g_tRw.g.cs deleted file mode 100644 index 4c4616bb7d5..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mocha.Analyzers/Mocha.Analyzers.MediatorGenerator/BenchmarksMediatorBuilderExtensions._RXvJz6gQPQLNfJu4g_tRw.g.cs +++ /dev/null @@ -1,49 +0,0 @@ -// - -#nullable enable -#pragma warning disable - -namespace Microsoft.Extensions.DependencyInjection -{ - [global::System.CodeDom.Compiler.GeneratedCode("Mocha.Analyzers", "0.0.0.0")] - public static class BenchmarksMediatorBuilderExtensions - { - public static global::Mocha.Mediator.IMediatorHostBuilder AddBenchmarks( - this global::Mocha.Mediator.IMediatorHostBuilder builder) - { - var services = builder.Services; - var lifetime = builder.Options.ServiceLifetime; - - // Register handlers - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.ICommandHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkCommandHandler), lifetime)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.ICommandHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineCommandHandler), lifetime)); - - // Register notification handlers - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkNotificationHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkNotificationHandler), lifetime)); - - // Register pipelines - global::Mocha.Mediator.MediatorHostBuilderExtensions.ConfigureMediator(builder, static b => - { - b.RegisterPipeline(new global::Mocha.Mediator.MediatorPipelineConfiguration - { - MessageType = typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkCommand), - ResponseType = typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkResponse), - Terminal = global::Mocha.Mediator.PipelineBuilder.BuildCommandTerminal() - }); - b.RegisterPipeline(new global::Mocha.Mediator.MediatorPipelineConfiguration - { - MessageType = typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineCommand), - ResponseType = typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkResponse), - Terminal = global::Mocha.Mediator.PipelineBuilder.BuildCommandTerminal() - }); - b.RegisterPipeline(new global::Mocha.Mediator.MediatorPipelineConfiguration - { - MessageType = typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkNotification), - Terminal = global::Mocha.Mediator.PipelineBuilder.BuildNotificationTerminal(new global::System.Type[] { typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkNotificationHandler) }) - }); - }); - - return builder; - } - } -} diff --git a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mocha.Analyzers/Mocha.Analyzers.MediatorGenerator/BenchmarksMediatorBuilderExtensions.g.cs b/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mocha.Analyzers/Mocha.Analyzers.MediatorGenerator/BenchmarksMediatorBuilderExtensions.g.cs deleted file mode 100644 index 7e036874fe4..00000000000 --- a/src/Mocha/benchmarks/Mocha.Mediator.Benchmarks/Generated/Mocha.Analyzers/Mocha.Analyzers.MediatorGenerator/BenchmarksMediatorBuilderExtensions.g.cs +++ /dev/null @@ -1,35 +0,0 @@ -// - -#nullable enable -#pragma warning disable - -namespace Microsoft.Extensions.DependencyInjection -{ - [global::System.CodeDom.Compiler.GeneratedCode("Mocha.Analyzers", "0.0.0.0")] - public static class BenchmarksMediatorBuilderExtensions - { - public static global::Mocha.Mediator.IMediatorHostBuilder AddBenchmarks( - this global::Mocha.Mediator.IMediatorHostBuilder builder) - { - var services = builder.Services; - var lifetime = builder.Options.ServiceLifetime; - - // Register handlers - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.ICommandHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkCommandHandler), lifetime)); - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.ICommandHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineCommandHandler), lifetime)); - - // Register notification handlers - services.Add(new global::Microsoft.Extensions.DependencyInjection.ServiceDescriptor(typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkNotificationHandler), typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkNotificationHandler), lifetime)); - - // Register pipelines - global::Mocha.Mediator.MediatorHostBuilderExtensions.ConfigureMediator(builder, static b => - { - b.RegisterPipeline(typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkCommand), global::Mocha.Mediator.PipelineBuilder.BuildCommandTerminal()); - b.RegisterPipeline(typeof(global::Mocha.Mediator.Benchmarks.Messaging.FullPipelineCommand), global::Mocha.Mediator.PipelineBuilder.BuildCommandTerminal()); - b.RegisterPipeline(typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkNotification), global::Mocha.Mediator.PipelineBuilder.BuildNotificationTerminal(new global::System.Type[] { typeof(global::Mocha.Mediator.Benchmarks.Messaging.BenchmarkNotificationHandler) })); - }); - - return builder; - } - } -}