|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using Shuttle.Core.Container; |
3 | 4 | using Shuttle.Core.Contract; |
4 | 5 | using Shuttle.Core.Pipelines; |
@@ -158,16 +159,36 @@ public static void Register(IComponentRegistry registry, IEventStoreConfiguratio |
158 | 159 | registry.Register(type, type, Lifestyle.Transient); |
159 | 160 | } |
160 | 161 |
|
| 162 | + var observers = new List<Type>(); |
| 163 | + |
161 | 164 | foreach (var type in reflectionService.GetTypesAssignableTo<IPipelineObserver>(typeof(EventStore).Assembly)) |
162 | 165 | { |
163 | | - if (type.IsInterface || registry.IsRegistered(type)) |
| 166 | + if (type.IsInterface || type.IsAbstract) |
164 | 167 | { |
165 | 168 | continue; |
166 | 169 | } |
167 | 170 |
|
168 | | - registry.Register(type, type, Lifestyle.Singleton); |
| 171 | + var interfaceType = type.InterfaceMatching($"I{type.Name}"); |
| 172 | + |
| 173 | + if (interfaceType != null) |
| 174 | + { |
| 175 | + if (registry.IsRegistered(type)) |
| 176 | + { |
| 177 | + continue; |
| 178 | + } |
| 179 | + |
| 180 | + registry.Register(interfaceType, type, Lifestyle.Singleton); |
| 181 | + } |
| 182 | + else |
| 183 | + { |
| 184 | + throw new ApplicationException(string.Format(Resources.ObserverInterfaceMissingException, type.Name)); |
| 185 | + } |
| 186 | + |
| 187 | + observers.Add(type); |
169 | 188 | } |
170 | 189 |
|
| 190 | + registry.RegisterCollection(typeof(IPipelineObserver), observers, Lifestyle.Singleton); |
| 191 | + |
171 | 192 | registry.AttemptRegister<IEventStore, EventStore>(); |
172 | 193 | registry.AttemptRegister<IEventProcessor, EventProcessor>(); |
173 | 194 | } |
|
0 commit comments