using Microsoft.Extensions.DependencyInjection;
using Svrnty.CQRS.Events.Abstractions;
namespace Svrnty.CQRS.Events.Kafka;
///
/// Extension methods for registering Kafka domain event publishing.
///
public static class ServiceCollectionExtensions
{
///
/// Adds Kafka domain event publishing to the service collection.
///
/// The service collection.
/// Optional configuration action for Kafka options.
/// The service collection for chaining.
public static IServiceCollection AddKafkaDomainEvents(
this IServiceCollection services,
Action? configure = null)
{
if (configure != null)
{
services.Configure(configure);
}
services.AddSingleton();
return services;
}
///
/// Adds Kafka domain event publishing with custom topic mapping.
///
/// The service collection.
/// Custom function to map event type names to topic names.
/// Optional configuration action for other Kafka options.
/// The service collection for chaining.
public static IServiceCollection AddKafkaDomainEvents(
this IServiceCollection services,
Func topicMapper,
Action? configure = null)
{
services.Configure(options =>
{
options.TopicMapper = topicMapper;
configure?.Invoke(options);
});
services.AddSingleton();
return services;
}
}