4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

SFEOS Game Pub/Sub Development Building Block

SFEOSPlanet.jpg

New Feature: Developer Building Blocks

  • This repository is a sub repository in the SFEOS github organization and is meant to be a building block example repository that SFEOS prototype developers can use to implement a very simple pub/sub event bus system without the overhead of an actual event bus. It uses MediatR, which in turn uses Dependency Injection to register and handle event publishing to subscribers. This repository follows the DDD (Domain Driven Design) Domain Events pattern (you can read more about it here).

Summary of Its Use

  • First you must add the Event class to the Dependency Injection Container. The Event class can hold any data that needs to be published to the subscribers.
services.AddMediatR(typeof(ScannerEventCompleted));
  • Once you have the Event class added you can publish a message to any subscriber class(es) that might be interested in the event.
_mediator.Publish(new ScannerEventCompleted("Some result from the scan."));
  • Any service or aggregate can subscribe to the event by inheriting from the NotificationHandler and then implementing the HandleCore method.
public class NotificationService : NotificationHandler<ScannerEventCompleted>
{
    protected override void HandleCore(ScannerEventCompleted message)
    {
        // do anything that needs done after the event happened.
    }
}



Posted on Utopian.io - Rewarding Open Source Contributors

10 upvotes $0.26

Replies (2)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: