Last active
August 29, 2015 13:56
-
-
Save jjvdangelo/9224409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CommandBus = | |
let createCommandRouter handlers = | |
let event = Event<Command>() | |
handlers |> List.iter(fun handler -> event.Publish |> Event.add handler) | |
let agent = MailboxProcessor.Start(fun inbox -> | |
let loop() = async { | |
let! cmd = inbox.Receive() | |
cmd |> event.Trigger | |
return! loop() } | |
loop()) | |
{ new IRounter<Command> with | |
member __.Send (cmd: Command) = | |
cmd |> agent.Post } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Issuer = | |
| System | |
| User of username: string | |
override this.ToString() = | |
match this with | |
| System -> "System" // Replace "System" with what ever you'd like | |
| User name -> name | |
type CommandData = { EntityId: Guid; Issuer: Issuer } | |
type Command = { Data: CommandData; Body: obj } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Simple.Web.StructureMap | |
type DomainStartup() = | |
inherit StructureMapStartupBase() | |
let commandRouter = | |
[ MyDomain.createHandler1; | |
MyDomain.createHandler2; | |
MyDomain.createHandler3; ] | |
|> CommandBus.createCommandRouter | |
override __.Configure(config) = | |
config.For(typedefof<IRouter<Command>>).Singleton().Use(commandRouter) |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type IRouter<'a> = | |
abstract Send: 'a -> unit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment