-
Notifications
You must be signed in to change notification settings - Fork 160
/
StreamServicesExtensions.cs
149 lines (116 loc) · 6.28 KB
/
StreamServicesExtensions.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Steeltoe.Common.Contexts;
using Steeltoe.Common.Expression.Internal;
using Steeltoe.Common.Expression.Internal.Spring.Standard;
using Steeltoe.Common.Expression.Internal.Spring.Support;
using Steeltoe.Common.Lifecycle;
using Steeltoe.Connector.RabbitMQ;
using Steeltoe.Integration.Extensions;
using Steeltoe.Integration.Support.Converter;
using Steeltoe.Messaging;
using Steeltoe.Messaging.Converter;
using Steeltoe.Messaging.Core;
using Steeltoe.Messaging.Handler.Attributes.Support;
using Steeltoe.Messaging.RabbitMQ.Extensions;
using Steeltoe.Stream.Binding;
using Steeltoe.Stream.Config;
using Steeltoe.Stream.Converter;
using System;
namespace Steeltoe.Stream.Extensions;
public static class StreamServicesExtensions
{
public static void AddStreamConfiguration(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<SpringIntegrationOptions>(configuration.GetSection(SpringIntegrationOptions.PREFIX));
services.Configure<BindingServiceOptions>(configuration.GetSection(BindingServiceOptions.PREFIX));
services.PostConfigure<BindingServiceOptions>(o => o.PostProcess());
}
public static void AddStreamCoreServices(this IServiceCollection services, IConfiguration configuration)
{
// ContentTypeConfiguration
services.TryAddSingleton<IMessageConverterFactory, CompositeMessageConverterFactory>();
services.TryAddSingleton<ConfigurableCompositeMessageConverter>();
services.AddSingleton<ISmartMessageConverter>((p) => p.GetRequiredService<ConfigurableCompositeMessageConverter>());
// SpelExpressionConverterConfiguration ?
// messageHandlerFactoryMethod
services.TryAddSingleton<IMessageHandlerMethodFactory, StreamMessageHandlerMethodFactory>();
// messageConverterConfigurer
services.TryAddSingleton<MessageConverterConfigurer>();
services.TryAddSingleton<IMessageChannelConfigurer>((p) => p.GetRequiredService<MessageConverterConfigurer>());
// compositeMessageChannelConfigurer
services.TryAddSingleton<CompositeMessageChannelConfigurer>();
// channelFactory
services.TryAddSingleton<SubscribableChannelBindingTargetFactory>();
services.AddSingleton<IBindingTargetFactory>((p) => p.GetRequiredService<SubscribableChannelBindingTargetFactory>());
// messageSourceFactory
services.TryAddSingleton<MessageSourceBindingTargetFactory>();
services.AddSingleton<IBindingTargetFactory>((p) => p.GetRequiredService<MessageSourceBindingTargetFactory>());
// binderAwareChannelResolver
services.TryAddSingleton<BinderAwareChannelResolver>();
services.TryAddSingleton<IDestinationResolver<IMessageChannel>>((p) => p.GetRequiredService<BinderAwareChannelResolver>());
// bindingService
services.TryAddSingleton<BindingService>();
services.TryAddSingleton<IBindingService>((p) => p.GetRequiredService<BindingService>());
// dynamicDestinationsBindable
services.TryAddSingleton<DynamicDestinationsBindable>();
services.AddSingleton<IBindable>((p) => p.GetRequiredService<DynamicDestinationsBindable>());
// spelPropertyAccessorRegistrar
// messageChannelStreamListenerResultAdapter
services.TryAddSingleton<MessageChannelStreamListenerResultAdapter>();
services.AddSingleton<IStreamListenerResultAdapter>((p) => p.GetRequiredService<MessageChannelStreamListenerResultAdapter>());
// outputBindingLifecycle
services.TryAddSingleton<OutputBindingLifecycle>();
services.AddSingleton<ILifecycle>((p) => p.GetRequiredService<OutputBindingLifecycle>());
// inputBindingLifecycle
services.TryAddSingleton<InputBindingLifecycle>();
services.AddSingleton<ILifecycle>((p) => p.GetRequiredService<InputBindingLifecycle>());
// contextStartAfterRefreshListener
// binderAwareRouterBeanPostProcessor
// appListener (TODO: This addNotPropagatedHeaders to AbstractReplyProducingMessageHandler(s) on context refresh
// defaultPoller in ChannelBindingAutoConfiguration ? (PollerMetadata) // DefaultPollerProperties
// streamListenerAnnotationBeanPostProcessor
services.TryAddSingleton<StreamListenerAttributeProcessor>();
}
public static void AddStreamServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddStreamConfiguration(configuration);
services.AddCoreServices();
services.AddIntegrationServices();
services.AddBinderServices(configuration);
services.AddStreamCoreServices(configuration);
}
public static void AddStreamServices<T>(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions();
services.SafeAddRabbitMQConnection(configuration);
services.AddRabbitConnectionFactory();
services.ConfigureRabbitOptions(configuration);
services.AddSingleton<IApplicationContext, GenericApplicationContext>();
services.AddStreamServices(configuration);
services.AddSourceStreamBinding();
services.AddSinkStreamBinding();
services.AddSingleton<IExpressionParser, SpelExpressionParser>();
services.AddSingleton<IEvaluationContext, StandardEvaluationContext>();
services.AddEnableBinding<T>();
}
// Deal with intermittent TypeLoadExceptions in Connectors (mac, linux)s
public static void SafeAddRabbitMQConnection(this IServiceCollection services, IConfiguration configuration)
{
var loggerFactory = services.BuildServiceProvider().GetService<ILoggerFactory>();
var logger = loggerFactory?.CreateLogger("Steeltoe.Stream.Extensions.SafeAddRabbitMQConnection");
try
{
services.AddRabbitMQConnection(configuration);
}
catch (Exception ex)
{
logger?.LogWarning(ex, ex.Message);
}
}
}