@@ -109,7 +109,7 @@ private async Task InitializeEndpointIfNecessary(FunctionExecutionContext execut
109109 LogManager . GetLogger ( "Previews" ) . Info (
110110 "NServiceBus.AzureFunctions.ServiceBus is a preview package. Preview packages are licensed separately from the rest of the Particular Software platform and have different support guarantees. You can view the license at https://particular.net/eula/previews and the support policy at https://docs.particular.net/previews/support-policy. Customer adoption drives whether NServiceBus.AzureFunctions.ServiceBus will be incorporated into the Particular Software platform. Let us know you are using it, if you haven't already, by emailing us at [email protected] ." ) ; 111111
112- var endpoint = await endpointFactory ( executionContext ) . ConfigureAwait ( false ) ;
112+ endpoint = await endpointFactory ( executionContext ) . ConfigureAwait ( false ) ;
113113
114114 pipeline = configuration . PipelineInvoker ;
115115 }
@@ -121,6 +121,107 @@ private async Task InitializeEndpointIfNecessary(FunctionExecutionContext execut
121121 }
122122 }
123123
124+ /// <inheritdoc />
125+ public async Task Send ( object message , SendOptions options , ExecutionContext executionContext , ILogger functionsLogger = null )
126+ {
127+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
128+
129+ await endpoint . Send ( message , options ) . ConfigureAwait ( false ) ;
130+ }
131+
132+ /// <inheritdoc />
133+ public Task Send ( object message , ExecutionContext executionContext , ILogger functionsLogger = null )
134+ {
135+ return Send ( message , new SendOptions ( ) , executionContext , functionsLogger ) ;
136+ }
137+
138+ /// <inheritdoc />
139+ public async Task Send < T > ( Action < T > messageConstructor , SendOptions options , ExecutionContext executionContext , ILogger functionsLogger = null )
140+ {
141+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
142+
143+ await endpoint . Send ( messageConstructor , options ) . ConfigureAwait ( false ) ;
144+ }
145+
146+ /// <inheritdoc />
147+ public Task Send < T > ( Action < T > messageConstructor , ExecutionContext executionContext , ILogger functionsLogger = null )
148+ {
149+ return Send ( messageConstructor , new SendOptions ( ) , executionContext , functionsLogger ) ;
150+ }
151+
152+ /// <inheritdoc />
153+ public async Task Publish ( object message , PublishOptions options , ExecutionContext executionContext , ILogger functionsLogger = null )
154+ {
155+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
156+
157+ await endpoint . Publish ( message , options ) . ConfigureAwait ( false ) ;
158+ }
159+
160+ /// <inheritdoc />
161+ public async Task Publish < T > ( Action < T > messageConstructor , PublishOptions options , ExecutionContext executionContext , ILogger functionsLogger = null )
162+ {
163+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
164+
165+ await endpoint . Publish ( messageConstructor , options ) . ConfigureAwait ( false ) ;
166+ }
167+
168+ /// <inheritdoc />
169+ public async Task Publish ( object message , ExecutionContext executionContext , ILogger functionsLogger = null )
170+ {
171+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
172+
173+ await endpoint . Publish ( message ) . ConfigureAwait ( false ) ;
174+ }
175+
176+ /// <inheritdoc />
177+ public async Task Publish < T > ( Action < T > messageConstructor , ExecutionContext executionContext , ILogger functionsLogger = null )
178+ {
179+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
180+
181+ await endpoint . Publish ( messageConstructor ) . ConfigureAwait ( false ) ;
182+ }
183+
184+ /// <inheritdoc />
185+ public async Task Subscribe ( Type eventType , SubscribeOptions options , ExecutionContext executionContext , ILogger functionsLogger = null )
186+ {
187+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
188+
189+ await endpoint . Subscribe ( eventType , options ) . ConfigureAwait ( false ) ;
190+ }
191+
192+ /// <inheritdoc />
193+ public async Task Subscribe ( Type eventType , ExecutionContext executionContext , ILogger functionsLogger = null )
194+ {
195+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
196+
197+ await endpoint . Subscribe ( eventType ) . ConfigureAwait ( false ) ;
198+ }
199+
200+ /// <inheritdoc />
201+ public async Task Unsubscribe ( Type eventType , UnsubscribeOptions options , ExecutionContext executionContext , ILogger functionsLogger = null )
202+ {
203+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
204+
205+ await endpoint . Unsubscribe ( eventType , options ) . ConfigureAwait ( false ) ;
206+ }
207+
208+ /// <inheritdoc />
209+ public async Task Unsubscribe ( Type eventType , ExecutionContext executionContext , ILogger functionsLogger = null )
210+ {
211+ await InitializeEndpointUsedOutsideHandlerIfNecessary ( executionContext , functionsLogger ) . ConfigureAwait ( false ) ;
212+
213+ await endpoint . Unsubscribe ( eventType ) . ConfigureAwait ( false ) ;
214+ }
215+
216+ private async Task InitializeEndpointUsedOutsideHandlerIfNecessary ( ExecutionContext executionContext , ILogger functionsLogger )
217+ {
218+ FunctionsLoggerFactory . Instance . SetCurrentLogger ( functionsLogger ) ;
219+
220+ var functionExecutionContext = new FunctionExecutionContext ( executionContext , functionsLogger ) ;
221+
222+ await InitializeEndpointIfNecessary ( functionExecutionContext ) . ConfigureAwait ( false ) ;
223+ }
224+
124225 internal static void LoadAssemblies ( string assemblyDirectory )
125226 {
126227 var binFiles = Directory . EnumerateFiles (
@@ -189,5 +290,6 @@ static bool IsRuntimeAssembly(byte[] publicKeyToken)
189290 private ServiceBusTriggeredEndpointConfiguration configuration ;
190291
191292 PipelineInvoker pipeline ;
293+ private IEndpointInstance endpoint ;
192294 }
193295}
0 commit comments