It's been a while since I did any work on the Compact Framework, but every project I come across tends to fall into foolery because of the use of Forms. Anyway, I enjoy the ability to be able to fire off events from a Form so that actions on a form have side effects, you could sort of do this when actual Events in the traditional sense but then you are tightly coupling the form and the event. Using my library below, you can publish events from the form and then both the form and then EventHandlers can be independent from one another. This means you can fire the events off from anywhere (ie a test, or a different form) and you don't need to do any wiring up.
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
public class Main | |
private _bus as IEventBus | |
public sub New(IEventBus bus) | |
_bus = bus | |
end sub | |
private Sub click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuSave.Click | |
_bus.publish(new SomethingHappened() with { .Id = 1 }) | |
end sub | |
end class | |
public class SomethingHappened | |
public readonly Id as integer | |
public sub New(id as integer) | |
me.Id = id | |
end sub | |
end class | |
public class DoSomethingOnSomethingHappened | |
Implements IEventHandler(Of SomethingHappened) | |
sub handle(ByVal e As SomethingHappened) _ | |
Implements IEventHandler(Of SomethingHappened).Handle | |
' do something with the something happened event, save an entity, create a project, send an email | |
End Sub | |
end class |
Take a look at the code here: https://github.com/DominicFinn/Eventing
0 comments:
Post a Comment