private void _registerCommandHandlers(ContainerBuilder builder, Assembly[] allReferencedAssemblies)
            {
                builder.RegisterType <CommandHandlerFactory>().As <ICommandHandlerFactory>();

                // Register the open generic with a name so the
                // decorator can use it.
                builder.RegisterAssemblyTypes(allReferencedAssemblies)
                .As(type => type.GetInterfaces()
                    .Where(interfaceType => TypeExtensions.IsClosedTypeOf(interfaceType, typeof(ICommandHandler <>)))
                    .Select(interfaceType => new KeyedService("commandHandler", interfaceType)))
                .InstancePerLifetimeScope();

                // Register the generic decorator so it can wrap
                // the resolved named generics.
                builder.RegisterGenericDecorator(
                    typeof(CommandHandlerErrorHandlingDecorator <>),
                    typeof(ICommandHandler <>),
                    fromKey: "commandHandler")
                .Keyed("commandHandlerErrorDecorated", typeof(ICommandHandler <>));

                builder.RegisterGenericDecorator(
                    typeof(CommandHandlerLoggerDecorator <>),
                    typeof(ICommandHandler <>),
                    fromKey: "commandHandlerErrorDecorated");
            }
 public static List <Type> AllCommandsQueries()
 {
     return(ApplicationAssembly.GetTypes()
            .Where(t => t.IsClass && TypeExtensions.IsClosedTypeOf(t, typeof(IRequest <>)) && !t.IsAbstract)
            .ToList());
 }