c# - How to use Caliburn Micro's EventAggregator to send empty events (no payload)? -


i found articles , solutions question pertaining prism, didn't find pertaining caliburn micro. checked all questions here tagged caliburn.micro , eventaggregator, didn't find caliburn specific seemingly basic issue.

scenario: want publish events eventaggregator don't have information, other signaling happened.

problem: first, in caliburn micro, eventaggregator's publish() method requires instance of type sent. second, subscribing , handling events require implementation of ihandle<t> interface, t type of instances want receive. seems designed around publishing , handling actual data.

goal: able publish simple events without having create , instantiate multiple empty/dummy classes, , without having handle() unnecessary events need filter further conditionals.


my solution far

this want improve/replace. (obviously, solution problematic because creates tighter coupling around concrete classes, in use case not big issue, since it's small project singular publishing components given event, , eventaggregator serves other practical goals.)

i made generic signal<t> class implements singleton pattern, providing static instance of through instance property:

public class signal<t> {     public static readonly signal<t> instance = new signal<t>();      private signal() { } } 

so can publish events in following way (signalsourceclass example):

_eventaggregator.publishonuithread(signal<signalsourceclass>.instance); 

and handle events declaring implementation of ihandle<t> in following way:

ihandle<signal<signalsourceclass>> 

this way can send , receive "empty" events creating single signal class. (of course limited solution, since components can send 1 event way.)

i suspect solution primitive (well, let's call fact), , there better i'm overlooking.

just create enum possible signals want:

public enum projectsignals {     connected,     disconnected,     openned } 

then just

_eventaggregator.publishonuithread( projectsignals.connected ); 

and

class someclass : ihandle<projectsignals> {    public void handle( projectsignals signal )    {         switch (signal)         {             case connected:                 break;         }     } } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -