@@ -63,9 +63,7 @@ public static IEndpointConventionBuilder Subscribe<TEvent>(
6363 string appName )
6464 where TEvent : IntegrationEvent
6565 {
66- var daprOptions = builder . ServiceProvider . GetRequiredService < IOptions < DaprOptions > > ( ) . Value ;
67- EnsureDaprSubscribeHandlerMapped ( builder , daprOptions ) ;
68- EnsureEventBusRegistered ( builder , daprOptions ) ;
66+ builder . EnsureDaprEventBus ( ) ;
6967
7068 var result = builder
7169 . MapPost ( route , ( TEvent receivedEvent , IEventBus eventBus ) => eventBus . ReceiveAsync ( receivedEvent ) )
@@ -80,6 +78,8 @@ public static IEndpointConventionBuilder Subscribe<TEvent>(
8078 /// <param name="assemblies"><see cref="Assembly"/></param>
8179 public static void Subscribe ( this IEndpointRouteBuilder builder , params Assembly [ ] assemblies )
8280 {
81+ builder . EnsureDaprEventBus ( ) ;
82+
8383 var method = typeof ( EndPointExtensions ) . GetMethod (
8484 nameof ( Subscribe ) ,
8585 new [ ] { typeof ( IEndpointRouteBuilder ) , typeof ( string ) } ) ! ;
@@ -100,7 +100,7 @@ public static void Subscribe(this IEndpointRouteBuilder builder, params Assembly
100100 }
101101 }
102102
103- private static void EnsureEventBusRegistered ( IEndpointRouteBuilder builder , DaprOptions daprOptions )
103+ private static void EnsureEventBusRegistered ( this IEndpointRouteBuilder builder , DaprOptions daprOptions )
104104 {
105105 if ( daprOptions . IsEventBusRegistered )
106106 {
@@ -115,9 +115,10 @@ private static void EnsureEventBusRegistered(IEndpointRouteBuilder builder, Dapr
115115 }
116116
117117 daprOptions . IsEventBusRegistered = true ;
118+ return ;
118119 }
119120
120- private static void EnsureDaprSubscribeHandlerMapped ( IEndpointRouteBuilder builder , DaprOptions daprOptions )
121+ private static void EnsureDaprSubscribeHandlerMapped ( this IEndpointRouteBuilder builder , DaprOptions daprOptions )
121122 {
122123 if ( daprOptions . IsDaprSubscribeHandlerMapped )
123124 {
@@ -131,5 +132,16 @@ private static void EnsureDaprSubscribeHandlerMapped(IEndpointRouteBuilder build
131132
132133 builder . MapSubscribeHandler ( ) ;
133134 daprOptions . IsDaprSubscribeHandlerMapped = true ;
135+ return ;
136+ }
137+
138+ private static DaprOptions GetDaprOptions ( this IEndpointRouteBuilder builder )
139+ => builder . ServiceProvider . GetRequiredService < IOptions < DaprOptions > > ( ) . Value ;
140+
141+ private static void EnsureDaprEventBus ( this IEndpointRouteBuilder builder )
142+ {
143+ var options = builder . GetDaprOptions ( ) ;
144+ builder . EnsureDaprSubscribeHandlerMapped ( options ) ;
145+ builder . EnsureEventBusRegistered ( options ) ;
134146 }
135147}
0 commit comments