Example #1
0
            public void MapCommand(Type dispatcherType, int eventId, Type commandType)
            {
                if (!typeof(IEventDispatcher).IsAssignableFrom(dispatcherType))
                {
                    throw new Exception($"Type {dispatcherType} must implement IDispatcher.");
                }

                if (!typeof(ICommand).IsAssignableFrom(commandType))
                {
                    throw new Exception($"Type {commandType} must implement ICommand.");
                }

                if (!commandMappings.ContainsKey(dispatcherType))
                {
                    CommandMapping mapping = new CommandMapping(dispatcherType);
                    mapping.MapEvent(eventId, commandType);
                    commandMappings.Add(dispatcherType, mapping);
                }
                else
                {
                    CommandMapping mapping = commandMappings[dispatcherType];
                    mapping.MapEvent(eventId, commandType);
                }
            }