Skip to content

Improve event handling and the eventing API - #102

Open
KlaasWhite wants to merge 1 commit into
mainfrom
feature/events
Open

KlaasWhite wants to merge 1 commit into
mainfrom
feature/events

Conversation

@KlaasWhite

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Disposed named channels remain permanently retained, allowing memory growth when mods repeatedly create transient channel names.

1 open issue
What changed in this PR

This PR replaces event mediation with a typed event bus for cross-mod messaging, supporting multiple publishers and subscriptions created before publishers.

Changes:

  • Introduces IEventBus with default and named channels, without requiring a marker interface.
  • Reworks publisher and subscription handles and removes parallel publishing.
  • Updates modding guides and navigation for the new API.
File Description
StarMap.Core/​StarMapCore.cs Registers the new event bus service.
StarMap.Core/​Services/​Mediator.cs Implements typed buses, named channels, and disposable handles.
StarMap.Core/​API/​MediationService.cs Removes the old mediation wrapper.
StarMap.Core/​API/​EventBus.cs Adds the event bus service wrapper.
StarMap.API/​Services/​IMediationService.cs Removes the old service interface.
StarMap.API/​Services/​IEventBus.cs Defines publisher and subscription operations.
StarMap.API/​Mediation/​ISubscription.cs Removes the constrained subscription interface.
StarMap.API/​Mediation/​IStarMapEvent.cs Removes the event marker interface.
StarMap.API/​Mediation/​IEventPublisher.cs Removes the previous publisher contract.
StarMap.API/​Events/​ISubscription.cs Adds an unconstrained subscription contract.
StarMap.API/​Events/​IEventPublisher.cs Adds the synchronous publisher contract.
mkdocs.yml Links navigation to the event bus guide.
docs/​modding/​services.md Updates the event service listing.
docs/​modding/​mod-services.md References the new built-in service.
docs/​modding/​lifecycle.md Updates injectable services and guide links.
docs/​modding/​index.md Links to the event bus guide.
docs/​modding/​event-mediation.md Removes the obsolete mediation guide.
docs/​modding/​event-bus.md Documents publishing, subscriptions, channels, and delivery.
docs/​modding/​dependencies.md Updates shared message contract requirements.
docs/​modding/​constructor-injection.md Lists IEventBus as an injectable service.

Review effort: Balanced

public EventBus<T> GetNamedBus(string eventName)
{
handler.Invoke(message);
return _namedBusses.GetOrAdd(eventName, (_) => new NamedEventBus<T>());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently busses remain in memory forever to reduce any thread risk coming with disposing and creation. In a future update this can be added to reduce memory, but the retained memory should be minimal. With no disposal, busses cannot be disconnected so no issues should arise

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants