In Memory
Simple in-memory event bus implementation in RCommon
Overview
Most enterprise applications have a need for a simple in-memory event bus which implements the observer pattern through the pub/sub pattern. RCommon implements a simple dependency-free event bus for this utility.
Configuration
using Examples.EventHandling.InMemoryEventBus;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using RCommon;
using RCommon.EventHandling;
using RCommon.EventHandling.Producers;
using System.Diagnostics;
using System.Reflection;
try
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, builder) =>
{
ConfigurationContainer.Configuration = builder
.Build();
})
.ConfigureServices(services =>
{
// Configure RCommon
services.AddRCommon()
.WithEventHandling<InMemoryEventBusBuilder>(eventHandling =>
{
eventHandling.AddProducer<PublishWithEventBusEventProducer>();
eventHandling.AddSubscriber<TestEvent, TestEventHandler>();
});
}).Build();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Implementation
Producing the Event
Subscribing to the Event
Event Handling: In MemoryLast updated