Compare commits
2
Commits
079048dff5
...
06c92f5eeb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06c92f5eeb | ||
|
|
28e679235c |
@@ -76,104 +76,6 @@ namespace xEventService.DI
|
|||||||
services.AddSingleton(configuration);
|
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,
|
|
||||||
IConfiguration configuration,
|
|
||||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var config = configuration.GetXEventServiceConfiguration();
|
|
||||||
source.AddEventService(
|
|
||||||
lifeTime: lifeTime,
|
|
||||||
configuration: config
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Event Consumer Service Registration ...
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TConsumer"></typeparam>
|
|
||||||
/// <param name="source"></param>
|
|
||||||
public static void AddXEventServiceConsumer<TConsumer>(
|
|
||||||
this IServiceCollection source
|
|
||||||
) where TConsumer : XBaseEventConsumerBackgroundService
|
|
||||||
{
|
|
||||||
//
|
|
||||||
var config = source.GetRegisteredService<XEventServiceConfiguration>();
|
|
||||||
if (config.IsNullOrDefault())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
Log("Consumer Registration Faild, due Invalid Configuration issue ...");
|
|
||||||
XException.InvalidConfiguration.Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
var consumerType = typeof(TConsumer);
|
|
||||||
switch (config.Broker)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case XEventBroker.XKafka:
|
|
||||||
//
|
|
||||||
if (!typeof(XKafkaConsumerServiceBase).IsAssignableFrom(consumerType))
|
|
||||||
{
|
|
||||||
//
|
|
||||||
Log($"Consumer Registration Failed. TConsumer must inherit from XKafkaConsumerServiceBase when Broker is {config.Broker.GetStringValue()} ...");
|
|
||||||
XException.InvalidConfiguration.Throw();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case XEventBroker.XZeroMQ:
|
|
||||||
if (!typeof(XZeroMQConsumerServiceBase).IsAssignableFrom(consumerType))
|
|
||||||
{
|
|
||||||
Log($"Consumer Registration Failed. TConsumer must inherit from XZeroMQConsumerServiceBase when Broker is {config.Broker.GetStringValue()} ...");
|
|
||||||
XException.InvalidConfiguration.Throw();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case XEventBroker.XRabbitMQ:
|
|
||||||
if (!typeof(XRabbitMQConsumerServiceBase).IsAssignableFrom(consumerType))
|
|
||||||
{
|
|
||||||
Log($"Consumer Registration Failed. TConsumer must inherit from XRabbitMQConsumerServiceBase when Broker is {config.Broker.GetStringValue()} ...");
|
|
||||||
XException.InvalidConfiguration.Throw();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
source.AddXBackgroundService<TConsumer>();
|
|
||||||
|
|
||||||
//
|
|
||||||
Log($"Consumer Registered Successfully: {consumerType.Name} for Broker: {config.Broker.GetStringValue()} ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
#region Private ...
|
#region Private ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -189,57 +91,6 @@ namespace xEventService.DI
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"{XLogTag} => {message}");
|
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
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Register Configuration ...
|
|
||||||
source.AddXEventServiceConfiguration(configuration);
|
|
||||||
|
|
||||||
//
|
|
||||||
// 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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user