/// <summary>
        /// Creates the specified assemblies.
        /// </summary>
        /// <param name="assemblies">The assemblies.</param>
        /// <returns></returns>
        public HandlerRepository Create(IEnumerable <string> assemblies)
        {
            var handlerRepository = new HandlerRepository();

            foreach (var assemblyName in assemblies)
            {
                var assembly = Assembly.LoadFrom(string.Format(@"{0}/{1}", AppDomain.CurrentDomain.BaseDirectory, assemblyName));

                foreach (var type in assembly.GetTypes())
                {
                    var customAttributes = type.GetCustomAttributes(typeof(DynamicHandlerAttribute), true);
                    if (customAttributes.Length == 0)
                    {
                        var messageType = IsMessageHandler(type);
                        if (messageType != null)
                        {
                            _contextManager.AddComponent(type);
                            handlerRepository.AddHandler(messageType, type);
                        }
                    }
                    else
                    {
                        var dynamicHandler = (DynamicHandlerAttribute)customAttributes[0];
                        var dictionary     = HandlerCreatorInstance.Instance.CreateFrom(type, dynamicHandler.BaseType);
                        foreach (var dynHandler in dictionary)
                        {
                            _contextManager.AddComponent(dynHandler.Value);
                            handlerRepository.AddHandler(dynHandler.Key, dynHandler.Value);
                        }
                    }
                }
            }

            return(handlerRepository);
        }
Exemplo n.º 2
0
        public void AddHandler_GetHandlersByMessage()
        {
            var subject = new HandlerRepository();

            subject.AddHandler(typeof(MessageFake), typeof(FakeHandler));

            var handlers = subject.GetHandlersByMessage(typeof(MessageFake));

            Assert.IsTrue(handlers.Count(x => x == typeof(FakeHandler)) == 1);
        }