CommandBus 0.0.7

CommandBus 0.0.7

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2015
SPMSupports SPM

Maintained by Lucas Ortis.



  • By
  • Lucas Ortis

CommandBus

A light weight Command Bus implementation written in Swift

CommandBus?

The idea of a command bus is that you create command objects that represent what you want your application to do. Then, you toss it into the bus and the bus makes sure that the command object gets to where it needs to go.

So, the command goes in -> the bus hands it off to a handler -> and then the handler actually does the job. The command essentially represents a method call to your application layer.

You can have more informations here.

Installation

Usage

  • First, you have to create a json mapping file in order to associate yours Commands with their handler:
{
    "{CommandNameA}": "{CommandHandlerNameA}",
    "{CommandNameB}": "{CommandHandlerNameB}",
    "{CommandNameC}": "{CommandHandlerNameC}"
}
  • Then you can create your Command and inject it to the bus:
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        /*** Register to the Command event ***/
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "onCommandHandled:", name:"COMMAND_DONE", object: nil)

        /*** Create the CommandBus ***/
        let commandBus: CommandBus = CommandBus(configurationFileName: "configuration")!

        /*** Create your own Command ***/
        let customCommand: CustomCommand = CustomCommand()

        /*** Send your command to the CommandBus with your event name ***/
        commandBus.handle(command: customCommand, commandHandledEvent: "COMMAND_DONE")
    }

    func onCommandHandled(notification: NSNotification) {
        /*** This method is called when the CommandHandler have done ***/
        print("Command Handled: \(notification.object!)")
    }
}

You can also see the Example project.

Author

Ekhoo:

License

CommandBus is available under the MIT license. See the LICENSE file for more info.