EventFactory
EventFactory is a static utility that constructs new Event instances. It abstracts event creation and ensures consistent initialization. Call CreateEvent(domain, verbValue) when a system needs to send a message to another domain.
EventFactory.CreateEvent(Domain.Audio, 42).Params.Set(key, value);Event
Event is the core message type in EventSystem. Each event holds:
- A
TargetDomainthat determines which handler receives it - A
Verbcode identifying the specific action within that domain - A
Paramspayload containing typed data
Systems populate the payload using:
myEvent.Params.Set(CoreParamKeys.StringValue, "hello");
string retrieved = myEvent.Params.Get(CoreParamKeys.StringValue);Internally, Params is a dictionary-backed container using IParamKey as keys and boxed objects as values. Type safety is enforced through ParamKey<T> generics.
IEvent and IEventReceiver
IEvent is a marker interface that all events must implement. This allows EventBus to route any event-like object generically.
IEventReceiver defines the contract for listeners. Handlers implement OnEvent(Event e) to receive and process dispatched events:
public class MyAudioHandler : IEventReceiver
{
public void OnEvent(Event e)
{
if (e.Verb == AudioVerbs.PlaySound)
{
// handle the event
}
}
}Interaction Flow:
MyAudioHandlerregisters withEventBus(via subscription, obtained fromServiceLocator.GetBusRegistry().EventBus)- A feature creates an event:
EventFactory.CreateEvent(Domain.Audio, AudioVerbs.PlaySound) - The event is populated:
event.Params.Set(key, value) - The event is raised:
eventBus.Raise(event) EventBusroutes it to all handlers subscribed toDomain.AudioMyAudioHandler.OnEvent(event)is called- The handler retrieves parameters and executes its logic
The Params system ensures type-safe retrieval through generic casting; ParamKey<T> instances provide compile-time checking that the expected type matches.