Skip to content

Commit

Permalink
#40 Accessibility - refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kgniazdowski committed Mar 27, 2021
1 parent 8187016 commit 9fea2c9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
using System.Collections.Generic;
using Accessibility.Application;

namespace Accessibility.Api.Options
{
public class EventBusOptions
{
public EventBusOptions()
{
Exchanges = new Dictionary<string, string>();
Exchanges = new Dictionary<EventBusExchange, string>();
}
public const string EventBus = "EventBus";

public Dictionary<string, string> Exchanges { get; set; }
}

public enum EventBusExchange
{
BookingRequests
public Dictionary<EventBusExchange, string> Exchanges { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Accessibility.Application.Bookings.Commands.CreateBookingRequest
{
public class CreateBookingRequestCommand : IRequest
{
public CreateBookingRequestCommand(Guid customerId, Guid facilityId, List<BookedRecordDto> bookedRecords, Dictionary<string, string> eventBusExchanges)
public CreateBookingRequestCommand(Guid customerId, Guid facilityId, List<BookedRecordDto> bookedRecords, Dictionary<EventBusExchange, string> eventBusExchanges)
{
CustomerId = customerId;
FacilityId = facilityId;
Expand All @@ -17,6 +17,6 @@ public CreateBookingRequestCommand(Guid customerId, Guid facilityId, List<Booked
public Guid CustomerId { get; }
public Guid FacilityId { get; }
public List<BookedRecordDto> BookedRecords { get; }
public Dictionary<string, string> EventBusExchanges { get; }
public Dictionary<EventBusExchange, string> EventBusExchanges { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<Unit> Handle(CreateBookingRequestCommand request, Cancellation
await bookingRepository.AddAsync(booking);
await unitOfWork.CommitAsync();

var sendEndpoint = await sendEndpointProvider.GetSendEndpoint(new Uri($"exchange:{request.EventBusExchanges[EventBusExchange.BookingRequests.ToString()]}"));
var sendEndpoint = await sendEndpointProvider.GetSendEndpoint(new Uri($"exchange:{request.EventBusExchanges[EventBusExchange.BookingRequests]}"));

await sendEndpoint.Send(new BookingRequested(
facilityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Accessibility.Infrastructure
public static class Startup
{
// TODO: split registrations into modules
public static IServiceCollection ConfigureAccessibility(this IServiceCollection services, IConfiguration configuration, Assembly applicationAssembly, Dictionary<string, string> eventBusExchanges)
public static IServiceCollection ConfigureAccessibility(this IServiceCollection services, IConfiguration configuration, Assembly applicationAssembly, Dictionary<EventBusExchange, string> eventBusExchanges)
{
var connectionString = configuration.GetConnectionString("Accessibility");

Expand All @@ -62,7 +62,7 @@ public static IServiceCollection ConfigureAccessibility(this IServiceCollection
return services;
}

private static IServiceCollection ConfigureEventBus(this IServiceCollection services, IConfiguration configuration, Dictionary<string, string> eventBusExchanges)
private static IServiceCollection ConfigureEventBus(this IServiceCollection services, IConfiguration configuration, Dictionary<EventBusExchange, string> eventBusExchanges)
{
return services.AddMassTransit(x =>
{
Expand All @@ -78,7 +78,7 @@ private static IServiceCollection ConfigureEventBus(this IServiceCollection serv
cfgH.Password(configuration["RabbitMQ:Password"]);
});
cfg.ReceiveEndpoint(eventBusExchanges[EventBusExchange.BookingRequests.ToString()], e =>
cfg.ReceiveEndpoint(eventBusExchanges[EventBusExchange.BookingRequests], e =>
e.ConfigureConsumer<BookingRequestedConsumer>(context));
cfg.ReceiveEndpoint("offer-created-listener", e =>
Expand Down

0 comments on commit 9fea2c9

Please sign in to comment.