From c6b3968ad8b74988ef6abeee17daac4b4665f4cd Mon Sep 17 00:00:00 2001 From: Hank McCord Date: Thu, 16 Mar 2023 20:54:24 -0400 Subject: [PATCH] Fix runtime exception in DryIoc sample The addition of the second constructor in the Mediator class (for publishing strategies) breaks the default rules for DryIoc. This commit will fix that by explicity picking the constructor to use in the container. It also adds comments for an alternative solution to automatically resolve classes that have multiple constructors. --- samples/MediatR.Examples.DryIoc/Program.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/samples/MediatR.Examples.DryIoc/Program.cs b/samples/MediatR.Examples.DryIoc/Program.cs index 845c743b..55fba1a7 100644 --- a/samples/MediatR.Examples.DryIoc/Program.cs +++ b/samples/MediatR.Examples.DryIoc/Program.cs @@ -20,12 +20,17 @@ static Task Main() private static IMediator BuildMediator(WrappingWriter writer) { var container = new Container(); + // Since Mediator has multiple constructors, consider adding rule to allow that + // var container = new Container(rules => rules.With(FactoryMethod.ConstructorWithResolvableArguments)) container.Use(writer); //Pipeline works out of the box here container.RegisterMany(new[] { typeof(IMediator).GetAssembly(), typeof(Ping).GetAssembly() }, Registrator.Interfaces); + //Without the container having FactoryMethod.ConstructorWithResolvableArguments commented above + //You must select the desired constructor + container.Register(made: Made.Of(() => new Mediator(Arg.Of()))); var services = new ServiceCollection();