Exemplo n.º 1
0
 public static IEventReference Resolve(this IEventResolver resolver, IServiceDefinition serviceDefinition, EventId eventId)
 {
     if (resolver.TryResolve(serviceDefinition, eventId, out var eventReference))
     {
         return(eventReference);
     }
     throw new EventResolveException(serviceDefinition.Name, eventId);
 }
        private void EnumerateThroughPrimitiveType(
            IConfigurationSection parentSection, ConfigurationSectionKey serviceKey,
            PrimitiveType type, IServiceDefinition serviceDefinition,
            Dictionary <ConfigurationSectionKey, IConfigurationSection> map)
        {
            foreach (var section in parentSection.GetChildren())
            {
                if (section.Key.Equals("_all", StringComparison.OrdinalIgnoreCase))
                {
                    var allPrimitivesKey = serviceKey;
                    allPrimitivesKey.PrimitiveType = type;
                    map[allPrimitivesKey]          = section;
                }
                else if (type == PrimitiveType.Command || type == PrimitiveType.Query)
                {
                    var methodType = type;
                    var methodName = section.Key;

                    if (serviceDefinition != null && _methodResolver.TryResolve(serviceDefinition,
                                                                                new MethodId {
                        Name = methodName
                    }, out var methodReference))
                    {
                        methodType = methodReference.Definition.IsQuery ? PrimitiveType.Query : PrimitiveType.Command;
                        methodName = methodReference.Definition.Name;
                    }

                    var methodKey = serviceKey;
                    methodKey.PrimitiveType = methodType;
                    methodKey.PrimitiveName = methodName;

                    map[methodKey] = section;
                }
                else if (type == PrimitiveType.Event)
                {
                    var eventName = section.Key;

                    if (serviceDefinition != null && _eventResolver.TryResolve(serviceDefinition,
                                                                               new EventId {
                        Name = eventName
                    }, out var eventReference))
                    {
                        eventName = eventReference.Definition.Name;
                    }

                    var eventKey = serviceKey;
                    eventKey.PrimitiveType = type;
                    eventKey.PrimitiveName = eventName;

                    map[eventKey] = section;
                }
            }
        }