Eventing for VB.NET on the .NET Compact Framework

MC70
I don't know why I enjoy programming devices like this but I used to write stock management software for supermarkets using devices like this and I still sometimes have a hankering to go back to the Compact Framework and VB.NET days.

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.

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
view raw Eventing.vb hosted with ❤ by GitHub






Take a look at the code here: https://github.com/DominicFinn/Eventing
SHARE

Dom Finn

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment