Skip to content

Instantly share code, notes, and snippets.



Last active Jul 5, 2017
What would you like to do?
Register F# DU (Discriminated Union) cases as event types in Marten event store
module EventStore =
open Marten
open Microsoft.FSharp.Reflection
open System.Reflection
type Events =
| Event1 of string
| Event2 of int
let registerUnionCasesAsEvents<'a> (opts: StoreOptions) =
typedefof<'a>.GetNestedTypes(BindingFlags.Public ||| BindingFlags.NonPublic)
|> Array.filter FSharpType.IsUnion
|> Array.iter opts.Events.AddEventType
let getStore connectionString schemaName = DocumentStore.For (fun opts ->
opts.DatabaseSchemaName <- schemaName
opts.AutoCreateSchemaObjects <- AutoCreate.All
opts |> registerUnionCasesAsEvents<Events>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.