Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#126) udpate services registration #139

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public static IParalaxBuilder AddRabbitMq(this IParalaxBuilder builder, string s
builder.Services.AddSingleton<IConventionsRegistry, ConventionsRegistry>();
builder.Services.AddSingleton<MessageSubscribersChannel>();

builder.Services.AddSingleton<IBusPublisher, RabbitMqPublisher>();
builder.Services.AddSingleton<IBusSubscriber, RabbitMqSubscriber>();
builder.Services.AddSingleton<MessageSubscribersChannel>();
builder.Services.AddTransient<RabbitMqExchangeInitializer>();
builder.Services.AddHostedService<RabbitMqBackgroundService>();
builder.AddInitializer<RabbitMqExchangeInitializer>();


builder.Services.AddSingleton<IRabbitMqPropertiesFactory, RabbitMqPropertiesFactory>();
builder.Services.AddSingleton<IRabbitMqChannelFactory, RabbitMqChannelFactory>();
Expand Down Expand Up @@ -108,12 +115,7 @@ public static IParalaxBuilder AddRabbitMq(this IParalaxBuilder builder, string s
}

// Register other services that need to be shared
builder.Services.AddSingleton<IBusPublisher, RabbitMqPublisher>();
builder.Services.AddSingleton<IBusSubscriber, RabbitMqSubscriber>();
builder.Services.AddSingleton<MessageSubscribersChannel>();
builder.Services.AddTransient<RabbitMqExchangeInitializer>();
builder.Services.AddHostedService<RabbitMqBackgroundService>();
builder.AddInitializer<RabbitMqExchangeInitializer>();


return builder;
}
Expand Down Expand Up @@ -202,9 +204,13 @@ public static IBusSubscriber UseRabbitMq(this IApplicationBuilder app)
{
var messageSubscribersChannel = app.ApplicationServices.GetRequiredService<MessageSubscribersChannel>();

// Get all RabbitMQ clients and inject them into RabbitMqSubscriber
var clients = app.ApplicationServices.GetServices<IRabbitMqClient>();

if (!clients.Any())
{
throw new InvalidOperationException("No RabbitMQ clients have been registered.");
}

return new RabbitMqSubscriber(clients, messageSubscribersChannel);
}
}
Expand Down
Loading