Moved all the namespace to globalusings
This commit is contained in:
		
							parent
							
								
									6546b63aa4
								
							
						
					
					
						commit
						0fe244cc80
					
				| @ -1,26 +1,20 @@ | |||||||
| using Autofac; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.AutofacModules; | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |  | ||||||
| using Ordering.SignalrHub.IntegrationEvents; |  | ||||||
| using System.Reflection; |  | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.AutofacModules | public class ApplicationModule | ||||||
|  |     : Autofac.Module | ||||||
| { | { | ||||||
|     public class ApplicationModule | 
 | ||||||
|         : Autofac.Module |     public string QueriesConnectionString { get; } | ||||||
|  | 
 | ||||||
|  |     public ApplicationModule() | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected override void Load(ContainerBuilder builder) | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
|         public string QueriesConnectionString { get; } |         builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEvent).GetTypeInfo().Assembly) | ||||||
|  |             .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); | ||||||
| 
 | 
 | ||||||
|         public ApplicationModule() |  | ||||||
|         { |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         protected override void Load(ContainerBuilder builder) |  | ||||||
|         { |  | ||||||
| 
 |  | ||||||
|             builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEvent).GetTypeInfo().Assembly) |  | ||||||
|                 .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); |  | ||||||
| 
 |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,36 +1,28 @@ | |||||||
| using Microsoft.AspNetCore.SignalR; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents; | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Serilog.Context; |  | ||||||
| using System; |  | ||||||
| using System.Threading.Tasks; |  | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents | public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent> | ||||||
| { | { | ||||||
|     public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToAwaitingValidationIntegrationEvent> |     private readonly IHubContext<NotificationsHub> _hubContext; | ||||||
|  |     private readonly ILogger<OrderStatusChangedToAwaitingValidationIntegrationEventHandler> _logger; | ||||||
|  | 
 | ||||||
|  |     public OrderStatusChangedToAwaitingValidationIntegrationEventHandler( | ||||||
|  |         IHubContext<NotificationsHub> hubContext, | ||||||
|  |         ILogger<OrderStatusChangedToAwaitingValidationIntegrationEventHandler> logger) | ||||||
|     { |     { | ||||||
|         private readonly IHubContext<NotificationsHub> _hubContext; |         _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); | ||||||
|         private readonly ILogger<OrderStatusChangedToAwaitingValidationIntegrationEventHandler> _logger; |         _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToAwaitingValidationIntegrationEventHandler( | 
 | ||||||
|             IHubContext<NotificationsHub> hubContext, |     public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event) | ||||||
|             ILogger<OrderStatusChangedToAwaitingValidationIntegrationEventHandler> logger) |     { | ||||||
|  |         using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | ||||||
|         { |         { | ||||||
|             _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); |             _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | ||||||
|             _logger = logger ?? throw new ArgumentNullException(nameof(logger)); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
| 
 |             await _hubContext.Clients | ||||||
|         public async Task Handle(OrderStatusChangedToAwaitingValidationIntegrationEvent @event) |                 .Group(@event.BuyerName) | ||||||
|         { |                 .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); | ||||||
|             using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) |  | ||||||
|             { |  | ||||||
|                 _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); |  | ||||||
| 
 |  | ||||||
|                 await _hubContext.Clients |  | ||||||
|                     .Group(@event.BuyerName) |  | ||||||
|                     .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,37 +1,28 @@ | |||||||
| using Microsoft.AspNetCore.SignalR; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling; | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Ordering.SignalrHub.IntegrationEvents.Events; |  | ||||||
| using Serilog.Context; |  | ||||||
| using System; |  | ||||||
| using System.Threading.Tasks; |  | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.EventHandling | public class OrderStatusChangedToCancelledIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToCancelledIntegrationEvent> | ||||||
| { | { | ||||||
|     public class OrderStatusChangedToCancelledIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToCancelledIntegrationEvent> |     private readonly IHubContext<NotificationsHub> _hubContext; | ||||||
|  |     private readonly ILogger<OrderStatusChangedToCancelledIntegrationEventHandler> _logger; | ||||||
|  | 
 | ||||||
|  |     public OrderStatusChangedToCancelledIntegrationEventHandler( | ||||||
|  |         IHubContext<NotificationsHub> hubContext, | ||||||
|  |         ILogger<OrderStatusChangedToCancelledIntegrationEventHandler> logger) | ||||||
|     { |     { | ||||||
|         private readonly IHubContext<NotificationsHub> _hubContext; |         _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); | ||||||
|         private readonly ILogger<OrderStatusChangedToCancelledIntegrationEventHandler> _logger; |         _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToCancelledIntegrationEventHandler( | 
 | ||||||
|             IHubContext<NotificationsHub> hubContext, |     public async Task Handle(OrderStatusChangedToCancelledIntegrationEvent @event) | ||||||
|             ILogger<OrderStatusChangedToCancelledIntegrationEventHandler> logger) |     { | ||||||
|  |         using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | ||||||
|         { |         { | ||||||
|             _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); |             _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | ||||||
|             _logger = logger ?? throw new ArgumentNullException(nameof(logger)); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
| 
 |             await _hubContext.Clients | ||||||
|         public async Task Handle(OrderStatusChangedToCancelledIntegrationEvent @event) |                 .Group(@event.BuyerName) | ||||||
|         { |                 .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); | ||||||
|             using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) |  | ||||||
|             { |  | ||||||
|                 _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); |  | ||||||
| 
 |  | ||||||
|                 await _hubContext.Clients |  | ||||||
|                     .Group(@event.BuyerName) |  | ||||||
|                     .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -1,37 +1,28 @@ | |||||||
| using Microsoft.AspNetCore.SignalR; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling; | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Ordering.SignalrHub.IntegrationEvents.Events; |  | ||||||
| using Serilog.Context; |  | ||||||
| using System; |  | ||||||
| using System.Threading.Tasks; |  | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.EventHandling | public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent> | ||||||
| { | { | ||||||
|     public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent> |     private readonly IHubContext<NotificationsHub> _hubContext; | ||||||
|  |     private readonly ILogger<OrderStatusChangedToPaidIntegrationEventHandler> _logger; | ||||||
|  | 
 | ||||||
|  |     public OrderStatusChangedToPaidIntegrationEventHandler( | ||||||
|  |         IHubContext<NotificationsHub> hubContext, | ||||||
|  |         ILogger<OrderStatusChangedToPaidIntegrationEventHandler> logger) | ||||||
|     { |     { | ||||||
|         private readonly IHubContext<NotificationsHub> _hubContext; |         _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); | ||||||
|         private readonly ILogger<OrderStatusChangedToPaidIntegrationEventHandler> _logger; |         _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToPaidIntegrationEventHandler( | 
 | ||||||
|             IHubContext<NotificationsHub> hubContext, |     public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event) | ||||||
|             ILogger<OrderStatusChangedToPaidIntegrationEventHandler> logger) |     { | ||||||
|  |         using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | ||||||
|         { |         { | ||||||
|             _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); |             _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | ||||||
|             _logger = logger ?? throw new ArgumentNullException(nameof(logger)); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
| 
 |             await _hubContext.Clients | ||||||
|         public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event) |                 .Group(@event.BuyerName) | ||||||
|         { |                 .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); | ||||||
|             using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) |  | ||||||
|             { |  | ||||||
|                 _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); |  | ||||||
| 
 |  | ||||||
|                 await _hubContext.Clients |  | ||||||
|                     .Group(@event.BuyerName) |  | ||||||
|                     .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,37 +1,28 @@ | |||||||
| using Microsoft.AspNetCore.SignalR; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling; | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Ordering.SignalrHub.IntegrationEvents.Events; |  | ||||||
| using Serilog.Context; |  | ||||||
| using System; |  | ||||||
| using System.Threading.Tasks; |  | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.EventHandling | public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToShippedIntegrationEvent> | ||||||
| { | { | ||||||
|     public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToShippedIntegrationEvent> |     private readonly IHubContext<NotificationsHub> _hubContext; | ||||||
|  |     private readonly ILogger<OrderStatusChangedToShippedIntegrationEventHandler> _logger; | ||||||
|  | 
 | ||||||
|  |     public OrderStatusChangedToShippedIntegrationEventHandler( | ||||||
|  |         IHubContext<NotificationsHub> hubContext, | ||||||
|  |         ILogger<OrderStatusChangedToShippedIntegrationEventHandler> logger) | ||||||
|     { |     { | ||||||
|         private readonly IHubContext<NotificationsHub> _hubContext; |         _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); | ||||||
|         private readonly ILogger<OrderStatusChangedToShippedIntegrationEventHandler> _logger; |         _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToShippedIntegrationEventHandler( | 
 | ||||||
|             IHubContext<NotificationsHub> hubContext, |     public async Task Handle(OrderStatusChangedToShippedIntegrationEvent @event) | ||||||
|             ILogger<OrderStatusChangedToShippedIntegrationEventHandler> logger) |     { | ||||||
|  |         using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | ||||||
|         { |         { | ||||||
|             _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); |             _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | ||||||
|             _logger = logger ?? throw new ArgumentNullException(nameof(logger)); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
| 
 |             await _hubContext.Clients | ||||||
|         public async Task Handle(OrderStatusChangedToShippedIntegrationEvent @event) |                 .Group(@event.BuyerName) | ||||||
|         { |                 .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); | ||||||
|             using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) |  | ||||||
|             { |  | ||||||
|                 _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); |  | ||||||
| 
 |  | ||||||
|                 await _hubContext.Clients |  | ||||||
|                     .Group(@event.BuyerName) |  | ||||||
|                     .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,38 +1,29 @@ | |||||||
| using Microsoft.AspNetCore.SignalR; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling; | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Ordering.SignalrHub.IntegrationEvents.Events; |  | ||||||
| using Serilog.Context; |  | ||||||
| using System; |  | ||||||
| using System.Threading.Tasks; |  | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.EventHandling | public class OrderStatusChangedToStockConfirmedIntegrationEventHandler : | ||||||
|  |     IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent> | ||||||
| { | { | ||||||
|     public class OrderStatusChangedToStockConfirmedIntegrationEventHandler : |     private readonly IHubContext<NotificationsHub> _hubContext; | ||||||
|         IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent> |     private readonly ILogger<OrderStatusChangedToStockConfirmedIntegrationEventHandler> _logger; | ||||||
|  | 
 | ||||||
|  |     public OrderStatusChangedToStockConfirmedIntegrationEventHandler( | ||||||
|  |         IHubContext<NotificationsHub> hubContext, | ||||||
|  |         ILogger<OrderStatusChangedToStockConfirmedIntegrationEventHandler> logger) | ||||||
|     { |     { | ||||||
|         private readonly IHubContext<NotificationsHub> _hubContext; |         _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); | ||||||
|         private readonly ILogger<OrderStatusChangedToStockConfirmedIntegrationEventHandler> _logger; |         _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToStockConfirmedIntegrationEventHandler( | 
 | ||||||
|             IHubContext<NotificationsHub> hubContext, |     public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event) | ||||||
|             ILogger<OrderStatusChangedToStockConfirmedIntegrationEventHandler> logger) |     { | ||||||
|  |         using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | ||||||
|         { |         { | ||||||
|             _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); |             _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | ||||||
|             _logger = logger ?? throw new ArgumentNullException(nameof(logger)); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
| 
 |             await _hubContext.Clients | ||||||
|         public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event) |                 .Group(@event.BuyerName) | ||||||
|         { |                 .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); | ||||||
|             using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) |  | ||||||
|             { |  | ||||||
|                 _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); |  | ||||||
| 
 |  | ||||||
|                 await _hubContext.Clients |  | ||||||
|                     .Group(@event.BuyerName) |  | ||||||
|                     .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,38 +1,28 @@ | |||||||
| using Microsoft.AspNetCore.SignalR; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.EventHandling; | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | public class OrderStatusChangedToSubmittedIntegrationEventHandler : | ||||||
| using Microsoft.Extensions.Logging; |     IIntegrationEventHandler<OrderStatusChangedToSubmittedIntegrationEvent> | ||||||
| using Ordering.SignalrHub.IntegrationEvents.Events; |  | ||||||
| using Serilog.Context; |  | ||||||
| using System; |  | ||||||
| using System.Threading.Tasks; |  | ||||||
| 
 |  | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.EventHandling |  | ||||||
| { | { | ||||||
|     public class OrderStatusChangedToSubmittedIntegrationEventHandler : |     private readonly IHubContext<NotificationsHub> _hubContext; | ||||||
|         IIntegrationEventHandler<OrderStatusChangedToSubmittedIntegrationEvent> |     private readonly ILogger<OrderStatusChangedToSubmittedIntegrationEventHandler> _logger; | ||||||
|  | 
 | ||||||
|  |     public OrderStatusChangedToSubmittedIntegrationEventHandler( | ||||||
|  |         IHubContext<NotificationsHub> hubContext, | ||||||
|  |         ILogger<OrderStatusChangedToSubmittedIntegrationEventHandler> logger) | ||||||
|     { |     { | ||||||
|         private readonly IHubContext<NotificationsHub> _hubContext; |         _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); | ||||||
|         private readonly ILogger<OrderStatusChangedToSubmittedIntegrationEventHandler> _logger; |         _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToSubmittedIntegrationEventHandler( | 
 | ||||||
|             IHubContext<NotificationsHub> hubContext, |     public async Task Handle(OrderStatusChangedToSubmittedIntegrationEvent @event) | ||||||
|             ILogger<OrderStatusChangedToSubmittedIntegrationEventHandler> logger) |     { | ||||||
|  |         using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) | ||||||
|         { |         { | ||||||
|             _hubContext = hubContext ?? throw new ArgumentNullException(nameof(hubContext)); |             _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); | ||||||
|             _logger = logger ?? throw new ArgumentNullException(nameof(logger)); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
| 
 |             await _hubContext.Clients | ||||||
|         public async Task Handle(OrderStatusChangedToSubmittedIntegrationEvent @event) |                 .Group(@event.BuyerName) | ||||||
|         { |                 .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); | ||||||
|             using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) |  | ||||||
|             { |  | ||||||
|                 _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); |  | ||||||
| 
 |  | ||||||
|                 await _hubContext.Clients |  | ||||||
|                     .Group(@event.BuyerName) |  | ||||||
|                     .SendAsync("UpdatedOrderState", new { OrderId = @event.OrderId, Status = @event.OrderStatus }); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -1,18 +1,15 @@ | |||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents; | ||||||
| 
 | public record OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents |  | ||||||
| { | { | ||||||
|     public record OrderStatusChangedToAwaitingValidationIntegrationEvent : IntegrationEvent |     public int OrderId { get; } | ||||||
|     { |     public string OrderStatus { get; } | ||||||
|         public int OrderId { get; } |     public string BuyerName { get; } | ||||||
|         public string OrderStatus { get; } |  | ||||||
|         public string BuyerName { get; } |  | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId, string orderStatus, string buyerName) |     public OrderStatusChangedToAwaitingValidationIntegrationEvent(int orderId, string orderStatus, string buyerName) | ||||||
|         { |     { | ||||||
|             OrderId = orderId; |         OrderId = orderId; | ||||||
|             OrderStatus = orderStatus; |         OrderStatus = orderStatus; | ||||||
|             BuyerName = buyerName; |         BuyerName = buyerName; | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -1,18 +1,16 @@ | |||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.Events; | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.Events | public record OrderStatusChangedToCancelledIntegrationEvent : IntegrationEvent | ||||||
| { | { | ||||||
|     public record OrderStatusChangedToCancelledIntegrationEvent : IntegrationEvent |     public int OrderId { get; } | ||||||
|     { |     public string OrderStatus { get; } | ||||||
|         public int OrderId { get; } |     public string BuyerName { get; } | ||||||
|         public string OrderStatus { get; } |  | ||||||
|         public string BuyerName { get; } |  | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToCancelledIntegrationEvent(int orderId, string orderStatus, string buyerName) |     public OrderStatusChangedToCancelledIntegrationEvent(int orderId, string orderStatus, string buyerName) | ||||||
|         { |     { | ||||||
|             OrderId = orderId; |         OrderId = orderId; | ||||||
|             OrderStatus = orderStatus; |         OrderStatus = orderStatus; | ||||||
|             BuyerName = buyerName; |         BuyerName = buyerName; | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -1,19 +1,16 @@ | |||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.Events; | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.Events | public record OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent | ||||||
| { | { | ||||||
|     public record OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent |     public int OrderId { get; } | ||||||
|     { |     public string OrderStatus { get; } | ||||||
|         public int OrderId { get; } |     public string BuyerName { get; } | ||||||
|         public string OrderStatus { get; } |  | ||||||
|         public string BuyerName { get; } |  | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToPaidIntegrationEvent(int orderId, |     public OrderStatusChangedToPaidIntegrationEvent(int orderId, | ||||||
|             string orderStatus, string buyerName) |         string orderStatus, string buyerName) | ||||||
|         { |     { | ||||||
|             OrderId = orderId; |         OrderId = orderId; | ||||||
|             OrderStatus = orderStatus; |         OrderStatus = orderStatus; | ||||||
|             BuyerName = buyerName; |         BuyerName = buyerName; | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,18 +1,16 @@ | |||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.Events; | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.Events | public record OrderStatusChangedToShippedIntegrationEvent : IntegrationEvent | ||||||
| { | { | ||||||
|     public record OrderStatusChangedToShippedIntegrationEvent : IntegrationEvent |     public int OrderId { get; } | ||||||
|     { |     public string OrderStatus { get; } | ||||||
|         public int OrderId { get; } |     public string BuyerName { get; } | ||||||
|         public string OrderStatus { get; } |  | ||||||
|         public string BuyerName { get; } |  | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToShippedIntegrationEvent(int orderId, string orderStatus, string buyerName) |     public OrderStatusChangedToShippedIntegrationEvent(int orderId, string orderStatus, string buyerName) | ||||||
|         { |     { | ||||||
|             OrderId = orderId; |         OrderId = orderId; | ||||||
|             OrderStatus = orderStatus; |         OrderStatus = orderStatus; | ||||||
|             BuyerName = buyerName; |         BuyerName = buyerName; | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -1,18 +1,15 @@ | |||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.Events; | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.Events | public record OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent | ||||||
| { | { | ||||||
|     public record OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent |     public int OrderId { get; } | ||||||
|     { |     public string OrderStatus { get; } | ||||||
|         public int OrderId { get; } |     public string BuyerName { get; } | ||||||
|         public string OrderStatus { get; } |  | ||||||
|         public string BuyerName { get; } |  | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId, string orderStatus, string buyerName) |     public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId, string orderStatus, string buyerName) | ||||||
|         { |     { | ||||||
|             OrderId = orderId; |         OrderId = orderId; | ||||||
|             OrderStatus = orderStatus; |         OrderStatus = orderStatus; | ||||||
|             BuyerName = buyerName; |         BuyerName = buyerName; | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,18 +1,15 @@ | |||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub.IntegrationEvents.Events; | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub.IntegrationEvents.Events | public record OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent | ||||||
| { | { | ||||||
|     public record OrderStatusChangedToSubmittedIntegrationEvent : IntegrationEvent |     public int OrderId { get; } | ||||||
|     { |     public string OrderStatus { get; } | ||||||
|         public int OrderId { get; } |     public string BuyerName { get; } | ||||||
|         public string OrderStatus { get; } |  | ||||||
|         public string BuyerName { get; } |  | ||||||
| 
 | 
 | ||||||
|         public OrderStatusChangedToSubmittedIntegrationEvent(int orderId, string orderStatus, string buyerName) |     public OrderStatusChangedToSubmittedIntegrationEvent(int orderId, string orderStatus, string buyerName) | ||||||
|         { |     { | ||||||
|             OrderId = orderId; |         OrderId = orderId; | ||||||
|             OrderStatus = orderStatus; |         OrderStatus = orderStatus; | ||||||
|             BuyerName = buyerName; |         BuyerName = buyerName; | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,24 +1,18 @@ | |||||||
| using Microsoft.AspNetCore.Authorization; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub; | ||||||
| using Microsoft.AspNetCore.SignalR; |  | ||||||
| using System; |  | ||||||
| using System.Threading.Tasks; |  | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub | [Authorize] | ||||||
|  | public class NotificationsHub : Hub | ||||||
| { | { | ||||||
|     [Authorize] | 
 | ||||||
|     public class NotificationsHub : Hub |     public override async Task OnConnectedAsync() | ||||||
|     { |     { | ||||||
|  |         await Groups.AddToGroupAsync(Context.ConnectionId, Context.User.Identity.Name); | ||||||
|  |         await base.OnConnectedAsync(); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         public override async Task OnConnectedAsync() |     public override async Task OnDisconnectedAsync(Exception ex) | ||||||
|         { |     { | ||||||
|             await Groups.AddToGroupAsync(Context.ConnectionId, Context.User.Identity.Name); |         await Groups.RemoveFromGroupAsync(Context.ConnectionId, Context.User.Identity.Name); | ||||||
|             await base.OnConnectedAsync(); |         await base.OnDisconnectedAsync(ex); | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         public override async Task OnDisconnectedAsync(Exception ex) |  | ||||||
|         { |  | ||||||
|             await Groups.RemoveFromGroupAsync(Context.ConnectionId, Context.User.Identity.Name); |  | ||||||
|             await base.OnDisconnectedAsync(ex); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,12 +1,4 @@ | |||||||
| using Microsoft.AspNetCore; | var configuration = GetConfiguration(); | ||||||
| using Microsoft.AspNetCore.Hosting; |  | ||||||
| using Microsoft.Extensions.Configuration; |  | ||||||
| using Serilog; |  | ||||||
| using System; |  | ||||||
| using System.IO; |  | ||||||
| using Ordering.SignalrHub; |  | ||||||
| 
 |  | ||||||
| var configuration = GetConfiguration(); |  | ||||||
| 
 | 
 | ||||||
| Log.Logger = CreateSerilogLogger(configuration); | Log.Logger = CreateSerilogLogger(configuration); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,274 +1,249 @@ | |||||||
| using Autofac; | namespace Microsoft.eShopOnContainers.Services.Ordering.SignalrHub; | ||||||
| using Autofac.Extensions.DependencyInjection; |  | ||||||
| using HealthChecks.UI.Client; |  | ||||||
| using Microsoft.AspNetCore.Authentication.JwtBearer; |  | ||||||
| using Microsoft.AspNetCore.Builder; |  | ||||||
| using Microsoft.AspNetCore.Diagnostics.HealthChecks; |  | ||||||
| using Microsoft.Azure.ServiceBus; |  | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; |  | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |  | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; |  | ||||||
| using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; |  | ||||||
| using Microsoft.Extensions.Configuration; |  | ||||||
| using Microsoft.Extensions.DependencyInjection; |  | ||||||
| using Microsoft.Extensions.Diagnostics.HealthChecks; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Ordering.SignalrHub.AutofacModules; |  | ||||||
| using Ordering.SignalrHub.IntegrationEvents; |  | ||||||
| using Ordering.SignalrHub.IntegrationEvents.EventHandling; |  | ||||||
| using Ordering.SignalrHub.IntegrationEvents.Events; |  | ||||||
| using RabbitMQ.Client; |  | ||||||
| using System; |  | ||||||
| using System.IdentityModel.Tokens.Jwt; |  | ||||||
| using System.Threading.Tasks; |  | ||||||
| 
 | 
 | ||||||
| namespace Ordering.SignalrHub | public class Startup | ||||||
| { | { | ||||||
|     public class Startup |     public Startup(IConfiguration configuration) | ||||||
|     { |     { | ||||||
|         public Startup(IConfiguration configuration) |         Configuration = configuration; | ||||||
|         { |     } | ||||||
|             Configuration = configuration; |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         public IConfiguration Configuration { get; } |     public IConfiguration Configuration { get; } | ||||||
| 
 | 
 | ||||||
|         // This method gets called by the runtime. Use this method to add services to the container. |     // This method gets called by the runtime. Use this method to add services to the container. | ||||||
|         // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 |     // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | ||||||
|         public IServiceProvider ConfigureServices(IServiceCollection services) |     public IServiceProvider ConfigureServices(IServiceCollection services) | ||||||
|  |     { | ||||||
|  |         services | ||||||
|  |             .AddCustomHealthCheck(Configuration) | ||||||
|  |             .AddCors(options => | ||||||
|  |             { | ||||||
|  |                 options.AddPolicy("CorsPolicy", | ||||||
|  |                     builder => builder | ||||||
|  |                     .AllowAnyMethod() | ||||||
|  |                     .AllowAnyHeader() | ||||||
|  |                     .SetIsOriginAllowed((host) => true) | ||||||
|  |                     .AllowCredentials()); | ||||||
|  |             }); | ||||||
|  | 
 | ||||||
|  |         if (Configuration.GetValue<string>("IsClusterEnv") == bool.TrueString) | ||||||
|         { |         { | ||||||
|             services |             services | ||||||
|                 .AddCustomHealthCheck(Configuration) |                 .AddSignalR() | ||||||
|                 .AddCors(options => |                 .AddStackExchangeRedis(Configuration["SignalrStoreConnectionString"]); | ||||||
|                 { |         } | ||||||
|                     options.AddPolicy("CorsPolicy", |         else | ||||||
|                         builder => builder |         { | ||||||
|                         .AllowAnyMethod() |             services.AddSignalR(); | ||||||
|                         .AllowAnyHeader() |  | ||||||
|                         .SetIsOriginAllowed((host) => true) |  | ||||||
|                         .AllowCredentials()); |  | ||||||
|                 }); |  | ||||||
| 
 |  | ||||||
|             if (Configuration.GetValue<string>("IsClusterEnv") == bool.TrueString) |  | ||||||
|             { |  | ||||||
|                 services |  | ||||||
|                     .AddSignalR() |  | ||||||
|                     .AddStackExchangeRedis(Configuration["SignalrStoreConnectionString"]); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 services.AddSignalR(); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) |  | ||||||
|             { |  | ||||||
|                 services.AddSingleton<IServiceBusPersisterConnection>(sp => |  | ||||||
|                 { |  | ||||||
|                     var serviceBusConnectionString = Configuration["EventBusConnection"]; |  | ||||||
|                     var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString); |  | ||||||
| 
 |  | ||||||
|                     var subscriptionClientName = Configuration["SubscriptionClientName"]; |  | ||||||
| 
 |  | ||||||
|                     return new DefaultServiceBusPersisterConnection(serviceBusConnection, subscriptionClientName); |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 services.AddSingleton<IRabbitMQPersistentConnection>(sp => |  | ||||||
|                 { |  | ||||||
|                     var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>(); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|                     var factory = new ConnectionFactory() |  | ||||||
|                     { |  | ||||||
|                         HostName = Configuration["EventBusConnection"], |  | ||||||
|                         DispatchConsumersAsync = true |  | ||||||
|                     }; |  | ||||||
| 
 |  | ||||||
|                     if (!string.IsNullOrEmpty(Configuration["EventBusUserName"])) |  | ||||||
|                     { |  | ||||||
|                         factory.UserName = Configuration["EventBusUserName"]; |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     if (!string.IsNullOrEmpty(Configuration["EventBusPassword"])) |  | ||||||
|                     { |  | ||||||
|                         factory.Password = Configuration["EventBusPassword"]; |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     var retryCount = 5; |  | ||||||
|                     if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) |  | ||||||
|                     { |  | ||||||
|                         retryCount = int.Parse(Configuration["EventBusRetryCount"]); |  | ||||||
|                     } |  | ||||||
| 
 |  | ||||||
|                     return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             ConfigureAuthService(services); |  | ||||||
| 
 |  | ||||||
|             RegisterEventBus(services); |  | ||||||
| 
 |  | ||||||
|             services.AddOptions(); |  | ||||||
| 
 |  | ||||||
|             //configure autofac |  | ||||||
|             var container = new ContainerBuilder(); |  | ||||||
|             container.RegisterModule(new ApplicationModule()); |  | ||||||
|             container.Populate(services); |  | ||||||
| 
 |  | ||||||
|             return new AutofacServiceProvider(container.Build()); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |         if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) | ||||||
|         public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |  | ||||||
|         { |         { | ||||||
|             //loggerFactory.AddConsole(Configuration.GetSection("Logging")); |             services.AddSingleton<IServiceBusPersisterConnection>(sp => | ||||||
|             //loggerFactory.AddDebug(); |  | ||||||
|             //loggerFactory.AddAzureWebAppDiagnostics(); |  | ||||||
|             //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); |  | ||||||
| 
 |  | ||||||
|             var pathBase = Configuration["PATH_BASE"]; |  | ||||||
| 
 |  | ||||||
|             if (!string.IsNullOrEmpty(pathBase)) |  | ||||||
|             { |             { | ||||||
|                 loggerFactory.CreateLogger<Startup>().LogDebug("Using PATH BASE '{pathBase}'", pathBase); |                 var serviceBusConnectionString = Configuration["EventBusConnection"]; | ||||||
|                 app.UsePathBase(pathBase); |                 var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString); | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             app.UseRouting(); |                 var subscriptionClientName = Configuration["SubscriptionClientName"]; | ||||||
|             app.UseCors("CorsPolicy"); |  | ||||||
|             app.UseAuthentication(); |  | ||||||
|             app.UseAuthorization(); |  | ||||||
| 
 | 
 | ||||||
|             app.UseEndpoints(endpoints => |                 return new DefaultServiceBusPersisterConnection(serviceBusConnection, subscriptionClientName); | ||||||
|             { |  | ||||||
|                 endpoints.MapHealthChecks("/hc", new HealthCheckOptions() |  | ||||||
|                 { |  | ||||||
|                     Predicate = _ => true, |  | ||||||
|                     ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse |  | ||||||
|                 }); |  | ||||||
|                 endpoints.MapHealthChecks("/liveness", new HealthCheckOptions |  | ||||||
|                 { |  | ||||||
|                     Predicate = r => r.Name.Contains("self") |  | ||||||
|                 }); |  | ||||||
|                 endpoints.MapHub<NotificationsHub>("/hub/notificationhub"); |  | ||||||
|             }); |             }); | ||||||
| 
 |  | ||||||
|             ConfigureEventBus(app); |  | ||||||
|         } |         } | ||||||
| 
 |         else | ||||||
|         private void ConfigureEventBus(IApplicationBuilder app) |  | ||||||
|         { |         { | ||||||
|             var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>(); |             services.AddSingleton<IRabbitMQPersistentConnection>(sp => | ||||||
| 
 |  | ||||||
|             eventBus.Subscribe<OrderStatusChangedToAwaitingValidationIntegrationEvent, OrderStatusChangedToAwaitingValidationIntegrationEventHandler>(); |  | ||||||
|             eventBus.Subscribe<OrderStatusChangedToPaidIntegrationEvent, OrderStatusChangedToPaidIntegrationEventHandler>(); |  | ||||||
|             eventBus.Subscribe<OrderStatusChangedToStockConfirmedIntegrationEvent, OrderStatusChangedToStockConfirmedIntegrationEventHandler>(); |  | ||||||
|             eventBus.Subscribe<OrderStatusChangedToShippedIntegrationEvent, OrderStatusChangedToShippedIntegrationEventHandler>(); |  | ||||||
|             eventBus.Subscribe<OrderStatusChangedToCancelledIntegrationEvent, OrderStatusChangedToCancelledIntegrationEventHandler>(); |  | ||||||
|             eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>(); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         private void ConfigureAuthService(IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             // prevent from mapping "sub" claim to nameidentifier. |  | ||||||
|             JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub"); |  | ||||||
| 
 |  | ||||||
|             var identityUrl = Configuration.GetValue<string>("IdentityUrl"); |  | ||||||
| 
 |  | ||||||
|             services.AddAuthentication(options => |  | ||||||
|             { |             { | ||||||
|                 options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; |                 var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>(); | ||||||
|                 options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; |  | ||||||
| 
 | 
 | ||||||
|             }).AddJwtBearer(options => | 
 | ||||||
|             { |                 var factory = new ConnectionFactory() | ||||||
|                 options.Authority = identityUrl; |  | ||||||
|                 options.RequireHttpsMetadata = false; |  | ||||||
|                 options.Audience = "orders.signalrhub"; |  | ||||||
|                 options.Events = new JwtBearerEvents |  | ||||||
|                 { |                 { | ||||||
|                     OnMessageReceived = context => |                     HostName = Configuration["EventBusConnection"], | ||||||
|                     { |                     DispatchConsumersAsync = true | ||||||
|                         var accessToken = context.Request.Query["access_token"]; |  | ||||||
| 
 |  | ||||||
|                         var path = context.HttpContext.Request.Path; |  | ||||||
|                         if (!string.IsNullOrEmpty(accessToken) && (path.StartsWithSegments("/hub/notificationhub"))) |  | ||||||
|                         { |  | ||||||
|                             context.Token = accessToken; |  | ||||||
|                         } |  | ||||||
|                         return Task.CompletedTask; |  | ||||||
|                     } |  | ||||||
|                 }; |                 }; | ||||||
|  | 
 | ||||||
|  |                 if (!string.IsNullOrEmpty(Configuration["EventBusUserName"])) | ||||||
|  |                 { | ||||||
|  |                     factory.UserName = Configuration["EventBusUserName"]; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 if (!string.IsNullOrEmpty(Configuration["EventBusPassword"])) | ||||||
|  |                 { | ||||||
|  |                     factory.Password = Configuration["EventBusPassword"]; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 var retryCount = 5; | ||||||
|  |                 if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) | ||||||
|  |                 { | ||||||
|  |                     retryCount = int.Parse(Configuration["EventBusRetryCount"]); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void RegisterEventBus(IServiceCollection services) |         ConfigureAuthService(services); | ||||||
|         { |  | ||||||
|             if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) |  | ||||||
|             { |  | ||||||
|                 services.AddSingleton<IEventBus, EventBusServiceBus>(sp => |  | ||||||
|                 { |  | ||||||
|                     var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>(); |  | ||||||
|                     var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); |  | ||||||
|                     var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>(); |  | ||||||
|                     var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |  | ||||||
| 
 | 
 | ||||||
|                     return new EventBusServiceBus(serviceBusPersisterConnection, logger, |         RegisterEventBus(services); | ||||||
|                         eventBusSubcriptionsManager, iLifetimeScope); |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 services.AddSingleton<IEventBus, EventBusRabbitMQ>(sp => |  | ||||||
|                 { |  | ||||||
|                     var subscriptionClientName = Configuration["SubscriptionClientName"]; |  | ||||||
|                     var rabbitMQPersistentConnection = sp.GetRequiredService<IRabbitMQPersistentConnection>(); |  | ||||||
|                     var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); |  | ||||||
|                     var logger = sp.GetRequiredService<ILogger<EventBusRabbitMQ>>(); |  | ||||||
|                     var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |  | ||||||
| 
 | 
 | ||||||
|                     var retryCount = 5; |         services.AddOptions(); | ||||||
|                     if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) |  | ||||||
|                     { |  | ||||||
|                         retryCount = int.Parse(Configuration["EventBusRetryCount"]); |  | ||||||
|                     } |  | ||||||
| 
 | 
 | ||||||
|                     return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager, subscriptionClientName, retryCount); |         //configure autofac | ||||||
|                 }); |         var container = new ContainerBuilder(); | ||||||
|             } |         container.RegisterModule(new ApplicationModule()); | ||||||
|  |         container.Populate(services); | ||||||
| 
 | 
 | ||||||
|             services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); |         return new AutofacServiceProvider(container.Build()); | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static class CustomExtensionMethods |     // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||||||
|  |     public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) | ||||||
|     { |     { | ||||||
|         public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) |         //loggerFactory.AddConsole(Configuration.GetSection("Logging")); | ||||||
|  |         //loggerFactory.AddDebug(); | ||||||
|  |         //loggerFactory.AddAzureWebAppDiagnostics(); | ||||||
|  |         //loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); | ||||||
|  | 
 | ||||||
|  |         var pathBase = Configuration["PATH_BASE"]; | ||||||
|  | 
 | ||||||
|  |         if (!string.IsNullOrEmpty(pathBase)) | ||||||
|         { |         { | ||||||
|             var hcBuilder = services.AddHealthChecks(); |             loggerFactory.CreateLogger<Startup>().LogDebug("Using PATH BASE '{pathBase}'", pathBase); | ||||||
| 
 |             app.UsePathBase(pathBase); | ||||||
|             hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); |  | ||||||
| 
 |  | ||||||
|             if (configuration.GetValue<bool>("AzureServiceBusEnabled")) |  | ||||||
|             { |  | ||||||
|                 hcBuilder |  | ||||||
|                     .AddAzureServiceBusTopic( |  | ||||||
|                         configuration["EventBusConnection"], |  | ||||||
|                         topicName: "eshop_event_bus", |  | ||||||
|                         name: "signalr-servicebus-check", |  | ||||||
|                         tags: new string[] { "servicebus" }); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 hcBuilder |  | ||||||
|                     .AddRabbitMQ( |  | ||||||
|                         $"amqp://{configuration["EventBusConnection"]}", |  | ||||||
|                         name: "signalr-rabbitmqbus-check", |  | ||||||
|                         tags: new string[] { "rabbitmqbus" }); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return services; |  | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         app.UseRouting(); | ||||||
|  |         app.UseCors("CorsPolicy"); | ||||||
|  |         app.UseAuthentication(); | ||||||
|  |         app.UseAuthorization(); | ||||||
|  | 
 | ||||||
|  |         app.UseEndpoints(endpoints => | ||||||
|  |         { | ||||||
|  |             endpoints.MapHealthChecks("/hc", new HealthCheckOptions() | ||||||
|  |             { | ||||||
|  |                 Predicate = _ => true, | ||||||
|  |                 ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse | ||||||
|  |             }); | ||||||
|  |             endpoints.MapHealthChecks("/liveness", new HealthCheckOptions | ||||||
|  |             { | ||||||
|  |                 Predicate = r => r.Name.Contains("self") | ||||||
|  |             }); | ||||||
|  |             endpoints.MapHub<NotificationsHub>("/hub/notificationhub"); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         ConfigureEventBus(app); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void ConfigureEventBus(IApplicationBuilder app) | ||||||
|  |     { | ||||||
|  |         var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>(); | ||||||
|  | 
 | ||||||
|  |         eventBus.Subscribe<OrderStatusChangedToAwaitingValidationIntegrationEvent, OrderStatusChangedToAwaitingValidationIntegrationEventHandler>(); | ||||||
|  |         eventBus.Subscribe<OrderStatusChangedToPaidIntegrationEvent, OrderStatusChangedToPaidIntegrationEventHandler>(); | ||||||
|  |         eventBus.Subscribe<OrderStatusChangedToStockConfirmedIntegrationEvent, OrderStatusChangedToStockConfirmedIntegrationEventHandler>(); | ||||||
|  |         eventBus.Subscribe<OrderStatusChangedToShippedIntegrationEvent, OrderStatusChangedToShippedIntegrationEventHandler>(); | ||||||
|  |         eventBus.Subscribe<OrderStatusChangedToCancelledIntegrationEvent, OrderStatusChangedToCancelledIntegrationEventHandler>(); | ||||||
|  |         eventBus.Subscribe<OrderStatusChangedToSubmittedIntegrationEvent, OrderStatusChangedToSubmittedIntegrationEventHandler>(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void ConfigureAuthService(IServiceCollection services) | ||||||
|  |     { | ||||||
|  |         // prevent from mapping "sub" claim to nameidentifier. | ||||||
|  |         JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub"); | ||||||
|  | 
 | ||||||
|  |         var identityUrl = Configuration.GetValue<string>("IdentityUrl"); | ||||||
|  | 
 | ||||||
|  |         services.AddAuthentication(options => | ||||||
|  |         { | ||||||
|  |             options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | ||||||
|  |             options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | ||||||
|  | 
 | ||||||
|  |         }).AddJwtBearer(options => | ||||||
|  |         { | ||||||
|  |             options.Authority = identityUrl; | ||||||
|  |             options.RequireHttpsMetadata = false; | ||||||
|  |             options.Audience = "orders.signalrhub"; | ||||||
|  |             options.Events = new JwtBearerEvents | ||||||
|  |             { | ||||||
|  |                 OnMessageReceived = context => | ||||||
|  |                 { | ||||||
|  |                     var accessToken = context.Request.Query["access_token"]; | ||||||
|  | 
 | ||||||
|  |                     var path = context.HttpContext.Request.Path; | ||||||
|  |                     if (!string.IsNullOrEmpty(accessToken) && (path.StartsWithSegments("/hub/notificationhub"))) | ||||||
|  |                     { | ||||||
|  |                         context.Token = accessToken; | ||||||
|  |                     } | ||||||
|  |                     return Task.CompletedTask; | ||||||
|  |                 } | ||||||
|  |             }; | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void RegisterEventBus(IServiceCollection services) | ||||||
|  |     { | ||||||
|  |         if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) | ||||||
|  |         { | ||||||
|  |             services.AddSingleton<IEventBus, EventBusServiceBus>(sp => | ||||||
|  |             { | ||||||
|  |                 var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>(); | ||||||
|  |                 var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); | ||||||
|  |                 var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>(); | ||||||
|  |                 var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); | ||||||
|  | 
 | ||||||
|  |                 return new EventBusServiceBus(serviceBusPersisterConnection, logger, | ||||||
|  |                     eventBusSubcriptionsManager, iLifetimeScope); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             services.AddSingleton<IEventBus, EventBusRabbitMQ>(sp => | ||||||
|  |             { | ||||||
|  |                 var subscriptionClientName = Configuration["SubscriptionClientName"]; | ||||||
|  |                 var rabbitMQPersistentConnection = sp.GetRequiredService<IRabbitMQPersistentConnection>(); | ||||||
|  |                 var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); | ||||||
|  |                 var logger = sp.GetRequiredService<ILogger<EventBusRabbitMQ>>(); | ||||||
|  |                 var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); | ||||||
|  | 
 | ||||||
|  |                 var retryCount = 5; | ||||||
|  |                 if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) | ||||||
|  |                 { | ||||||
|  |                     retryCount = int.Parse(Configuration["EventBusRetryCount"]); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager, subscriptionClientName, retryCount); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | public static class CustomExtensionMethods | ||||||
|  | { | ||||||
|  |     public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) | ||||||
|  |     { | ||||||
|  |         var hcBuilder = services.AddHealthChecks(); | ||||||
|  | 
 | ||||||
|  |         hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); | ||||||
|  | 
 | ||||||
|  |         if (configuration.GetValue<bool>("AzureServiceBusEnabled")) | ||||||
|  |         { | ||||||
|  |             hcBuilder | ||||||
|  |                 .AddAzureServiceBusTopic( | ||||||
|  |                     configuration["EventBusConnection"], | ||||||
|  |                     topicName: "eshop_event_bus", | ||||||
|  |                     name: "signalr-servicebus-check", | ||||||
|  |                     tags: new string[] { "servicebus" }); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             hcBuilder | ||||||
|  |                 .AddRabbitMQ( | ||||||
|  |                     $"amqp://{configuration["EventBusConnection"]}", | ||||||
|  |                     name: "signalr-rabbitmqbus-check", | ||||||
|  |                     tags: new string[] { "rabbitmqbus" }); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return services; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user