Brighter icon indicating copy to clipboard operation
Brighter copied to clipboard

Using DI to create handlers does not work in v9+

Open wozzo opened this issue 1 year ago • 3 comments

Describe the bug

We had v8.1.1399 installed. Just tried both 9.0.1 and 9.1.16, with the same results on each. Whenever the commandProcessor.Send(command); method is called we get an exception with the message "No handler factory defined.". I've checked and the subscriber registry does contain an appropriate mapping for the command to handler. No code changes between the attempts, only the package version. I've been unable to find a change log, or release notes that describe any breaking changes, and a review of the documentation leads me to believe we're doing the right thing still.

To Reproduce

Broken version With this version you'll get an exception as described below thrown on the Send method call. If you change the version of Brighter to 8.1.1399 then you'll get a NotImplementedException in the handler factory but this is because I've not implemented the handler factory here as it is not needed to demonstrate the bug. If the code gets to this point then it has found the handler type.

Exceptions (if any)

System.InvalidOperationException HResult=0x80131509 Message=No handler factory defined. Source=Paramore.Brighter StackTrace: at Paramore.Brighter.CommandProcessor.Send[T](T command) at Program.<>c.<<Main>$>b__0_0(IAmACommandProcessor commandProcessor) in C:\Projects\BrighterTest\WebApplication1\Program.cs:line 21 at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass36_0.<Create>b__0(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)

Further technical details

  • Brighter version 9.0.1+
  • Include the output of dotnet --info .NET SDK (reflecting any global.json): Version: 6.0.302 Commit: c857713418

Runtime Environment: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.302\

global.json file: Not found

Host: Version: 6.0.7 Architecture: x64 Commit: 0ec02c8c96

.NET SDKs installed: 6.0.300 [C:\Program Files\dotnet\sdk] 6.0.301 [C:\Program Files\dotnet\sdk] 6.0.302 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Download .NET: https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs: https://aka.ms/dotnet/runtimes-sdk-info

  • The OS (Window, Linux, MacOs, etc) Windows 11

wozzo avatar Aug 03 '22 14:08 wozzo

The IAmAHandlerFactory implementation needs to change to IAmAHandlerFactorySync. The documentation that's up seems to be out of date. I would also suggest an exception should be thrown on this line if neither of the _handlerFactoryAsync or _handlerFactorySync are set.

wozzo avatar Aug 03 '22 15:08 wozzo

Thanks for raising this @wozzo, we're currently overhauling the documentation we will make sure that this is clear. I will however make a change so that if both factories are not set we throw an exception to say that you must set at least one of them.

DevJonny avatar Aug 06 '22 12:08 DevJonny

Great. Thanks.

wozzo avatar Aug 06 '22 12:08 wozzo

@wozzo this will be in the next release, are you happy for me to close it off?

DevJonny avatar Aug 24 '22 15:08 DevJonny

@DevJonny ofcourse. Thanks for the swift response!

wozzo avatar Aug 24 '22 15:08 wozzo