CoreEvents 1.0.0
dotnet add package CoreEvents --version 1.0.0
NuGet\Install-Package CoreEvents -Version 1.0.0
<PackageReference Include="CoreEvents" Version="1.0.0" />
paket add CoreEvents --version 1.0.0
#r "nuget: CoreEvents, 1.0.0"
// Install CoreEvents as a Cake Addin
#addin nuget:?package=CoreEvents&version=1.0.0
// Install CoreEvents as a Cake Tool
#tool nuget:?package=CoreEvents&version=1.0.0
CoreEvents
This package is an implementation of event aggregator for .NET Core.
In this pattern the subscriber observes the event aggregator instead of the publisher and the publisher knows only about the event aggregator and not about the subscribers.
How to use
Run into the package manager console.
Install-Package CoreEvents -Version 1.0.0
Go to startup.cs and configure the service:
using CoreEvents;
using CoreEvents.Interfaces;
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSingleton<ICoreEvents, CoreEvent>();
}
The next step is to create a class that will serve as an argument for the event. This class needs to implement ICoreMessage:
using CoreEvents.Interfaces;
namespace Common.Events.Messages
{
public class MessageTest : ICoreMessage
{
public string LogMessage { get; set; } = "Hello World";
}
}
This is an example of a class subscribing to the previously created message:
public class MessageService
{
private readonly ICoreEvents _coreEvent;
public MessageService(ICoreEvents coreEvent)
{
_coreEvent = coreEvent;
// Subscribing the event
_coreEvent.Subscribe<MessageTest>(c => { MessageNotification(c); });
}
// This method will be called when someone publish MessageTest
private void MessageNotification(MessageTest message)
{
Console.WriteLine($"Received a notification from: {message.LogMessage}");
}
}
This is an example of the message being published:
public class PublishSample
{
private readonly ICoreEvents _coreEvent;
public PublishSample(ICoreEvents coreEvent)
{
_coreEvent = coreEvent;
// The message will be published for those who have subscribed to it
_coreEvent.Publish(new MessageTest());
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.2 is compatible. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.2
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 865 | 8/7/2019 |