add Register DI Producers ...
This commit is contained in:
@@ -5,6 +5,8 @@ using xCommons.Extensions;
|
||||
using xEventService.Configuration;
|
||||
using xEventService.Constants;
|
||||
using xEventService.Extensions;
|
||||
using xEventService.Interfaces;
|
||||
using xEventService.Providers;
|
||||
using xExceptions.Constants;
|
||||
|
||||
namespace xEventService.DI
|
||||
@@ -68,6 +70,25 @@ namespace xEventService.DI
|
||||
services.AddSingleton(configuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Service ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="lifeTime"></param>
|
||||
public static void AddXEventService(
|
||||
this IServiceCollection source,
|
||||
XEventServiceConfiguration configuration,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
)
|
||||
{
|
||||
//
|
||||
source.AddEventService(
|
||||
lifeTime: lifeTime,
|
||||
configuration: configuration
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
#region Private ...
|
||||
/// <summary>
|
||||
@@ -83,6 +104,62 @@ namespace xEventService.DI
|
||||
{
|
||||
Console.WriteLine($"{XLogTag} => {message}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Event Service ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="lifeTime"></param>
|
||||
private static void AddEventService(
|
||||
this IServiceCollection source,
|
||||
XEventServiceConfiguration configuration,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!configuration.IsValid())
|
||||
{
|
||||
//
|
||||
Log("Initialization Failed due Invalid Configuration ...");
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Register based on Broker ...
|
||||
switch (configuration.Broker)
|
||||
{
|
||||
//
|
||||
case XEventBroker.XKafka:
|
||||
source.Add(
|
||||
new ServiceDescriptor(typeof(IXKafkaProducerService), typeof(XKafkaProducerService), lifeTime)
|
||||
);
|
||||
break;
|
||||
|
||||
//
|
||||
case XEventBroker.XZeroMQ:
|
||||
source.Add(
|
||||
new ServiceDescriptor(typeof(IXZeroMQProducerService), typeof(XZeroMQProducerService), lifeTime)
|
||||
);
|
||||
break;
|
||||
|
||||
//
|
||||
case XEventBroker.XRabbitMQ:
|
||||
source.Add(
|
||||
new ServiceDescriptor(typeof(IXRabbitMQProducerService), typeof(XRabbitMQProducerService), lifeTime)
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
source.Add(
|
||||
new ServiceDescriptor(typeof(IXEventServiceProvider), typeof(XEventServiceProvider), lifeTime)
|
||||
);
|
||||
|
||||
//
|
||||
Log($"Service Registered Sucessfull, Provider: {configuration.Broker.GetStringValue()}");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user