CoreEvents 1.0.0

A simple implementation of event aggregator for .NET Core

Install-Package CoreEvents -Version 1.0.0
dotnet add package CoreEvents --version 1.0.0
<PackageReference Include="CoreEvents" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CoreEvents --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

alt text

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());
      }
  }

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.

alt text

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());
      }
  }

  • .NETCoreApp 2.2

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 67 8/7/2019