コード例 #1
0
 public TypedHandlerMiddleware(
     IDependencyResolver dependencyResolver,
     TypedHandlerConfiguration configuration)
 {
     this.dependencyResolver = dependencyResolver;
     this.configuration      = configuration;
 }
コード例 #2
0
        public TypedHandlerConfiguration Build()
        {
            var configuration = new TypedHandlerConfiguration();

            foreach (var handlerType in this.handlers)
            {
                this.dependencyConfigurator.Add(
                    handlerType,
                    handlerType,
                    this.serviceLifetime);

                var messageTypes = handlerType
                                   .GetInterfaces()
                                   .Where(x => x.IsGenericType && typeof(IMessageHandler).IsAssignableFrom(x))
                                   .Select(x => x.GenericTypeArguments[0]);

                foreach (var messageType in messageTypes)
                {
                    configuration.HandlerMapping.AddMapping(messageType, handlerType);
                }
            }

            return(configuration);
        }