示例#1
0
        private void InitializeMapsWithoutDependencyResolver(MessageScanner scanner)
        {
            foreach (var type in scanner.EventTypes)
            {
                nameToMessageTypePublishingEventMap.Add(type.FullName, type);
                messageTypeToNamePublishingEventMap.Add(type, type.FullName);
            }

            foreach (var type in scanner.CommandTypes)
            {
                nameToMessageTypeSendingCommandMap.Add(type.FullName, type);
                messageTypeToNameSendingCommandMap.Add(type, type.FullName);
            }
        }
示例#2
0
        public BusMessages(MessageScanRules messageScanRules, IDependencyResolver dependencyResolver)
        {
            var scanner = new MessageScanner(messageScanRules);

            scanner.Scan();

            if (!scanner.EventTypes.Any() && !scanner.CommandTypes.Any())
            {
                throw new TypeLoadException("Unable to find any messages. Properly define the message scan rules so it can be scanned properly.");
            }

            if (dependencyResolver == null)
            {
                InitializeMapsWithoutDependencyResolver(scanner);
            }
            else
            {
                InitializeMapsWithDependencyResolver(dependencyResolver, scanner);
            }
        }
示例#3
0
        public BusMessages(MessageScanRules messageScanRules)
        {
            var scanner = new MessageScanner(messageScanRules);

            scanner.Scan();

            var eventTypes = scanner.EventTypes;

            nameToMessageTypeEventMap = eventTypes.ToDictionary(e => e.FullName);
            messageTypeToNameEventMap = eventTypes.ToDictionary(e => e, e => e.FullName);

            var commandTypes = scanner.CommandTypes;

            nameToMessageTypeCommandMap = commandTypes.ToDictionary(e => e.FullName);
            messageTypeToNameCommandMap = commandTypes.ToDictionary(e => e, e => e.FullName);

            if (!eventTypes.Any() && !commandTypes.Any())
            {
                throw new TypeLoadException("Unable to find any messages. Properly define the message scan rules so it can be scanned properly.");
            }
        }
示例#4
0
        private void InitializeMapsWithDependencyResolver(IDependencyResolver dependencyResolver, MessageScanner scanner)
        {
            using (var resolver = dependencyResolver.CreateScope())
            {
                var creator = new MessageHandlerTypeCreator();
                foreach (var type in scanner.EventTypes)
                {
                    var isReceivingType = resolver.Resolve(creator.Create(type)) != null;
                    if (isReceivingType)
                    {
                        nameToMessageTypeReceivingEventMap.Add(type.FullName, type);
                        messageTypeToNameReceivingEventMap.Add(type, type.FullName);
                    }
                    else
                    {
                        nameToMessageTypePublishingEventMap.Add(type.FullName, type);
                        messageTypeToNamePublishingEventMap.Add(type, type.FullName);
                    }
                }

                foreach (var type in scanner.CommandTypes)
                {
                    var isReceivingType = resolver.Resolve(creator.Create(type)) != null;
                    if (isReceivingType)
                    {
                        nameToMessageTypeReceivingCommandMap.Add(type.FullName, type);
                        messageTypeToNameReceivingCommandMap.Add(type, type.FullName);
                    }
                    else
                    {
                        nameToMessageTypeSendingCommandMap.Add(type.FullName, type);
                        messageTypeToNameSendingCommandMap.Add(type, type.FullName);
                    }
                }
            }
        }