public static void RegisterExecutorsInAssembly(this CommandService target, Assembly asm) { var factory = new AttributeBasedMappingFactory(); foreach(var mappedCommand in asm.GetTypes().Where(t=>factory.IsCommandMapped(t))) { var executor = factory.CreateExecutorForCommand(mappedCommand); target.RegisterExecutor(mappedCommand, executor); } }
protected override Action <ICommand> GetCommandExecutorForCommand(Type commandType) { var registeredExecutor = base.GetCommandExecutorForCommand(commandType); if (registeredExecutor == null) { var factory = new AttributeBasedMappingFactory(); if (factory.IsCommandMapped(commandType)) { registeredExecutor = GetMappedExecutorAction(commandType); } } return(registeredExecutor); }
public void IsCommandMapped_should_return_false_for_non_command_types_that_do_have_the_required_attribute() { var factory = new AttributeBasedMappingFactory(); factory.IsCommandMapped(typeof(NonCommandTypeButWithCorrectAttribute)).Should().BeFalse(); }
public void IsCommandMapped_should_return_false_for_non_command_types() { var factory = new AttributeBasedMappingFactory(); factory.IsCommandMapped(typeof(string)).Should().BeFalse(); }
public void IsCommandMapped_should_return_true_for_correct_command_types_with_correct_attribute() { var factory = new AttributeBasedMappingFactory(); factory.IsCommandMapped(typeof(CommandTypeAndWithAttribute)).Should().BeTrue(); }