Skip to content

Instantly share code, notes, and snippets.

@otf
Created September 3, 2012 15:38
Show Gist options
  • Save otf/3610123 to your computer and use it in GitHub Desktop.
Save otf/3610123 to your computer and use it in GitHub Desktop.
type LogicalCallContextEvent<'T>() =
let id = Guid.NewGuid()
member this.Publish = this :> IDelegateEvent<Handler<'T>>
member this.Trigger(arg:'T) =
if CallContext.LogicalGetData(id.ToString()) <> null then
(CallContext.LogicalGetData(id.ToString()) :?> Handler<'T>).Invoke(this, arg)
interface IDelegateEvent<Handler<'T>> with
member this.AddHandler(handler : Handler<'T>) =
CallContext.LogicalSetData(id.ToString(), Delegate.Combine(CallContext.LogicalGetData(id.ToString()) :?> Handler<'T>, handler) :?> Handler<'T>)
member this.RemoveHandler(handler: Handler<'T>) =
CallContext.LogicalSetData(id.ToString(), Delegate.Remove(CallContext.LogicalGetData(id.ToString()) :?> Handler<'T>, handler) :?> Handler<'T>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment