/// <summary> /// Use RabbitMQ. /// Pass IApplicationLifetime.ApplicationStopping to this method. /// </summary> /// <param name="app"></param> /// <returns></returns> public static IApplicationBuilder UseConsul(this IApplicationBuilder app, CancellationToken applicationStopping) { _serviceDiscoveryHelper = _serviceDiscoveryHelper ?? app.ApplicationServices.GetRequiredService <IServiceDiscoveryHelper>(); _serviceDiscoveryHelper.RegisterAsync().GetAwaiter().GetResult(); applicationStopping.Register(() => { try { _serviceDiscoveryHelper.DeregisterAsync().GetAwaiter().GetResult(); } catch { // No action. } }); return(app); }
public override void PostInitialize() { consulHelper = IocManager.Resolve <IServiceDiscoveryHelper>(); AsyncHelper.RunSync(async() => await consulHelper.RegisterAsync()); }