-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
60 lines (54 loc) · 2.49 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
60 lines (54 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using BuslyCLI.Config;
using BuslyCLI.Config.Transports;
using BuslyCLI.Config.Validators;
using BuslyCLI.Infrastructure.Factories;
using FluentValidation;
using Microsoft.Extensions.DependencyInjection;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace BuslyCLI.Infrastructure;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddBuslyCLIServices(this IServiceCollection services)
{
services.AddScoped<IRawEndpointFactory, RawEndpointFactory>();
services.AddSingleton<INServiceBusConfiguration, NServiceBusConfiguration>();
services.AddValidatorsFromAssemblyContaining<RootConfigValidator>();
services.AddYamlDeserializer();
services.AddYamlSerializer();
return services;
}
private static IServiceCollection AddYamlDeserializer(this IServiceCollection services)
{
services.AddSingleton(
new DeserializerBuilder()
.IgnoreUnmatchedProperties()
.WithNamingConvention(HyphenatedNamingConvention.Instance)
.WithTypeDiscriminatingNodeDeserializer((o) =>
{
var keyMappings = new Dictionary<string, Type>
{
{ "learning-transport-config", typeof(LearningTransportConfig) },
{ "rabbitmq-transport-config", typeof(RabbitmqTransportConfig) },
{ "amazonsqs-transport-config", typeof(AmazonsqsTransportConfig) },
{ "azure-service-bus-transport-config", typeof(AzureServiceBusTransportConfig) },
{ "azure-storage-queues-transport-config", typeof(AzureStorageQueuesTransportConfig) },
{ "sql-server-transport-config", typeof(SqlServerTransportConfig) },
{ "postgre-sql-transport-config", typeof(PostgreSqlTransportConfig) }
};
o.AddUniqueKeyTypeDiscriminator<ITransportConfig>(keyMappings);
})
.Build());
return services;
}
private static IServiceCollection AddYamlSerializer(this IServiceCollection services)
{
services.AddSingleton(
new SerializerBuilder()
.WithIndentedSequences()
.WithNamingConvention(HyphenatedNamingConvention.Instance)
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull)
.Build());
return services;
}
}