@@ -46,12 +46,12 @@ public static void Execute(SourceProductionContext context, List<HandlerInfo> ha
4646 // Register handler in DI for non-static handler classes when lifetime != Singleton
4747 if ( registerHandlers && ! handler . IsStatic )
4848 {
49- var lifetimeMethod = "" ;
50- if ( string . Equals ( handlerLifetime , "Transient" , StringComparison . OrdinalIgnoreCase ) )
49+ string lifetimeMethod = "" ;
50+ if ( String . Equals ( handlerLifetime , "Transient" , StringComparison . OrdinalIgnoreCase ) )
5151 lifetimeMethod = "AddTransient" ;
52- if ( string . Equals ( handlerLifetime , "Scoped" , StringComparison . OrdinalIgnoreCase ) )
52+ if ( String . Equals ( handlerLifetime , "Scoped" , StringComparison . OrdinalIgnoreCase ) )
5353 lifetimeMethod = "AddScoped" ;
54- if ( string . Equals ( handlerLifetime , "Singleton" , StringComparison . OrdinalIgnoreCase ) )
54+ if ( String . Equals ( handlerLifetime , "Singleton" , StringComparison . OrdinalIgnoreCase ) )
5555 lifetimeMethod = "AddSingleton" ;
5656
5757 if ( ! String . IsNullOrEmpty ( lifetimeMethod ) )
@@ -61,21 +61,27 @@ public static void Execute(SourceProductionContext context, List<HandlerInfo> ha
6161 if ( handler . IsGenericHandlerClass )
6262 {
6363 // open generic registration
64- if ( handler . MessageGenericTypeDefinitionFullName != null && handler . GenericArity > 0 )
64+ if ( handler is not { MessageGenericTypeDefinitionFullName : not null , GenericArity : > 0 } )
65+ continue ;
66+
67+ // Build unbound generic typeof expressions
68+ string wrapperTypeOf = handler . GenericArity switch
6569 {
66- // Build unbound generic typeof expressions
67- var wrapperTypeOf = handler . GenericArity switch
68- {
69- 1 => $ "typeof({ handlerClassName } <>)",
70- 2 => $ "typeof({ handlerClassName } <,>)",
71- 3 => $ "typeof({ handlerClassName } <,,>)",
72- 4 => $ "typeof({ handlerClassName } <,,,>)",
73- _ => $ "typeof({ handlerClassName } <>)" // fallback
74- } ;
75- var msgTypeOf = $ "typeof({ handler . MessageGenericTypeDefinitionFullName } )";
76- source . AppendLine ( $ "// Open generic handler registration for { handler . MessageGenericTypeDefinitionFullName } ") ;
77- source . AppendLine ( $ "services.AddSingleton(new OpenGenericHandlerDescriptor({ msgTypeOf } , { wrapperTypeOf } , { handler . IsAsync . ToString ( ) . ToLower ( ) } ));") ;
78- }
70+ 1 => $ "typeof({ handlerClassName } <>)",
71+ 2 => $ "typeof({ handlerClassName } <,>)",
72+ 3 => $ "typeof({ handlerClassName } <,,>)",
73+ 4 => $ "typeof({ handlerClassName } <,,,>)",
74+ 5 => $ "typeof({ handlerClassName } <,,,,>)",
75+ 6 => $ "typeof({ handlerClassName } <,,,,,>)",
76+ 7 => $ "typeof({ handlerClassName } <,,,,,,>)",
77+ 8 => $ "typeof({ handlerClassName } <,,,,,,,>)",
78+ 9 => $ "typeof({ handlerClassName } <,,,,,,,,>)",
79+ 10 => $ "typeof({ handlerClassName } <,,,,,,,,,>)",
80+ _ => $ "typeof({ handlerClassName } <>)" // fallback
81+ } ;
82+ string msgTypeOf = $ "typeof({ handler . MessageGenericTypeDefinitionFullName } )";
83+ source . AppendLine ( $ "// Open generic handler registration for { handler . MessageGenericTypeDefinitionFullName } ") ;
84+ source . AppendLine ( $ "services.AddSingleton(new OpenGenericHandlerDescriptor({ msgTypeOf } , { wrapperTypeOf } , { handler . IsAsync . ToString ( ) . ToLower ( ) } ));") ;
7985 }
8086 else
8187 {
0 commit comments