In one project, we did the following:
There was a GlobalNotifier class that defined events that we wanted to use in different application modules, for example
public static class GlobalNotifier { public static event VoidEventHandler EnvrionmentChanged; public static void OnEnvrionmentChanged() { if (EnvrionmentChanged != null) { EnvrionmentChanged(); } } }
You can then raise this event anywhere you want the rest of the application to know that the environment has changed, for example
GlobalNotifier.OnEnvrionmentChanged();
You can also subscribe to this event, wherever you want to be notified that the environment has changed.
public ReportingService() { GlobalNotifier.EnvrionmentChanged += new VoidEventHandler(GlobalNotifier_EnvrionmentChanged); } void GlobalNotifier_EnvrionmentChanged() {
So, whenever you changed the environment, you raised this event, and everyone who should have known about this and performed some actions was notified. You may be similar to what you need to achieve.
Also, if you need to pass parameters, you can define the event in any way, basically -
public static event VoidEventHandler<SomeObject, List<OtherObject>> SomethingUpdated; public static void OnSomethingUpdated(SomeObject sender, List<OtherObject> associations) { if (SomethingUpdated != null) { SomethingUpdated(sender, associations); } }
source share