コード例 #1
0
 /// <summary>
 /// Use RabbitMQ.
 /// Pass IApplicationLifetime.ApplicationStopping to this method.
 /// </summary>
 /// <param name="app"></param>
 /// <returns></returns>
 public static IApplicationBuilder UseRabbitMQWithAutoSubscribe(this IApplicationBuilder app,
                                                                CancellationToken applicationStopping)
 {
     _connection = _connection ?? app.ApplicationServices.GetRequiredService <IRabbitMQPersistentConnection>();
     _connection.TryConnect();
     _messageSubscriber = _messageSubscriber ?? app.ApplicationServices.GetRequiredService <IMessageSubscriber>();
     _messageSubscriber.AutoSubscribe();
     applicationStopping.Register(_connection.Dispose);
     return(app);
 }