|
1 | | -using DispatchR.Abstractions.Notification; |
2 | | -using DispatchR.Abstractions.Send; |
| 1 | +using DispatchR.Abstractions.Send; |
3 | 2 | using Microsoft.Extensions.DependencyInjection; |
4 | 3 |
|
5 | 4 | namespace DispatchR.Configuration |
@@ -142,20 +141,23 @@ public static void RegisterHandlers(IServiceCollection services, List<Type> allT |
142 | 141 | } |
143 | 142 | } |
144 | 143 |
|
145 | | - services.AddScoped(handlerInterface, sp => |
146 | | - { |
147 | | - var keyedServices = sp.GetKeyedServices<IRequestHandler>(key); |
| 144 | + services.AddScoped(handlerInterface, sp => |
| 145 | + { |
| 146 | + var keyedServices = sp.GetKeyedServices<IRequestHandler>(key); |
148 | 147 |
|
149 | | - var pipelinesWithHandler = keyedServices as IRequestHandler[] ?? keyedServices.ToArray(); |
| 148 | + IReadOnlyList<IRequestHandler> pipelinesWithHandler = keyedServices switch |
| 149 | + { |
| 150 | + IRequestHandler[] asArray => asArray, |
| 151 | + IReadOnlyList<IRequestHandler> asList => asList, |
| 152 | + _ => keyedServices.ToArray() |
| 153 | + }; |
150 | 154 |
|
151 | | - // Single handler - no pipeline chaining needed |
152 | | - if (pipelinesWithHandler.Length == 1) |
153 | | - { |
154 | | - return pipelinesWithHandler[0]; |
155 | | - } |
| 155 | + // Single handler - no pipeline chaining needed |
| 156 | + if (pipelinesWithHandler.Count == 1) |
| 157 | + return pipelinesWithHandler[0]; |
156 | 158 |
|
157 | 159 | IRequestHandler lastPipeline = pipelinesWithHandler[0]; |
158 | | - for (int i = 1; i < pipelinesWithHandler.Length; i++) |
| 160 | + for (var i = 1; i < pipelinesWithHandler.Count; i++) |
159 | 161 | { |
160 | 162 | var pipeline = pipelinesWithHandler[i]; |
161 | 163 | pipeline.SetNext(lastPipeline); |
|
0 commit comments