Skip to content

Commit

Permalink
fix: Implementation of IEvent interface
Browse files Browse the repository at this point in the history
Each event must implement the IEvent interface
  • Loading branch information
QuentinCraft committed Dec 8, 2024
1 parent 18cf818 commit 1ddf2b7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 20 deletions.
10 changes: 5 additions & 5 deletions Luxoria.App/Luxoria.Modules/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EventBus : IEventBus
/// Publishes an event to all subscribed handlers.
/// Supports both synchronous and asynchronous execution.
/// </summary>
public async Task Publish<TEvent>(TEvent @event)
public async Task Publish<TEvent>(TEvent @event) where TEvent : IEvent
{
if (EqualityComparer<TEvent>.Default.Equals(@event, default(TEvent)))
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public async Task Publish<TEvent>(TEvent @event)
/// <summary>
/// Subscribes a synchronous handler to the specified event type.
/// </summary>
public void Subscribe<TEvent>(Action<TEvent> handler)
public void Subscribe<TEvent>(Action<TEvent> handler) where TEvent : IEvent
{
if (handler == null)
{
Expand All @@ -67,7 +67,7 @@ public void Subscribe<TEvent>(Action<TEvent> handler)
/// <summary>
/// Subscribes an asynchronous handler to the specified event type.
/// </summary>
public void Subscribe<TEvent>(Func<TEvent, Task> asyncHandler)
public void Subscribe<TEvent>(Func<TEvent, Task> asyncHandler) where TEvent : IEvent
{
if (asyncHandler == null)
{
Expand All @@ -86,7 +86,7 @@ public void Subscribe<TEvent>(Func<TEvent, Task> asyncHandler)
/// <summary>
/// Unsubscribes a synchronous handler from the specified event type.
/// </summary>
public void Unsubscribe<TEvent>(Action<TEvent> handler)
public void Unsubscribe<TEvent>(Action<TEvent> handler) where TEvent : IEvent
{
if (handler == null)
{
Expand All @@ -102,7 +102,7 @@ public void Unsubscribe<TEvent>(Action<TEvent> handler)
/// <summary>
/// Unsubscribes an asynchronous handler from the specified event type.
/// </summary>
public void Unsubscribe<TEvent>(Func<TEvent, Task> asyncHandler)
public void Unsubscribe<TEvent>(Func<TEvent, Task> asyncHandler) where TEvent : IEvent
{
if (asyncHandler == null)
{
Expand Down
8 changes: 8 additions & 0 deletions Luxoria.App/Luxoria.Modules/Interfaces/IEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Luxoria.Modules.Interfaces;

/// <summary>
/// Interface that represents an event that can be published and subscribed to
/// </summary>
public interface IEvent
{
}
10 changes: 5 additions & 5 deletions Luxoria.App/Luxoria.Modules/Interfaces/IEventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
public interface IEventBus
{
// Publishes an event to all subscribed handlers, supporting both async and sync.
Task Publish<TEvent>(TEvent @event);
Task Publish<TEvent>(TEvent @event) where TEvent : IEvent;

// Subscribes a synchronous handler to the event type.
void Subscribe<TEvent>(Action<TEvent> handler);
void Subscribe<TEvent>(Action<TEvent> handler) where TEvent : IEvent;

// Subscribes an asynchronous handler to the event type.
void Subscribe<TEvent>(Func<TEvent, Task> asyncHandler);
void Subscribe<TEvent>(Func<TEvent, Task> asyncHandler) where TEvent : IEvent;

// Unsubscribes a synchronous handler from the event type.
void Unsubscribe<TEvent>(Action<TEvent> handler);
void Unsubscribe<TEvent>(Action<TEvent> handler) where TEvent : IEvent;

// Unsubscribes an asynchronous handler from the event type.
void Unsubscribe<TEvent>(Func<TEvent, Task> asyncHandler);
void Unsubscribe<TEvent>(Func<TEvent, Task> asyncHandler) where TEvent : IEvent;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using Luxoria.Modules.Interfaces;
using System.Diagnostics.CodeAnalysis;

namespace Luxoria.Modules.Models.Events
{
[ExcludeFromCodeCoverage]
public class CollectionUpdatedEvent
public class CollectionUpdatedEvent : IEvent
{
/// <summary>
/// Collection name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using Luxoria.Modules.Interfaces;
using System.Diagnostics.CodeAnalysis;

namespace Luxoria.Modules.Models.Events
{
[ExcludeFromCodeCoverage]
public class ImageUpdatedEvent
public class ImageUpdatedEvent : IEvent
{
public string ImagePath { get; }

Expand Down
5 changes: 3 additions & 2 deletions Luxoria.App/Luxoria.Modules/Models/Events/LogEvent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using Luxoria.Modules.Interfaces;
using System.Diagnostics.CodeAnalysis;

namespace Luxoria.Modules.Models.Events
{
[ExcludeFromCodeCoverage]
public class LogEvent
public class LogEvent : IEvent
{
public string Message { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using Luxoria.Modules.Interfaces;
using System.Diagnostics.CodeAnalysis;

namespace Luxoria.Modules.Models.Events;

/// <summary>
/// Represents an event triggered when a collection is opened.
/// </summary>
[ExcludeFromCodeCoverage]
public class OpenCollectionEvent
public class OpenCollectionEvent : IEvent
{
// *** Properties ***

Expand Down
5 changes: 3 additions & 2 deletions Luxoria.App/Luxoria.Modules/Models/Events/TextInputEvent.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using Luxoria.Modules.Interfaces;
using System.Diagnostics.CodeAnalysis;

namespace Luxoria.Modules.Models.Events
{
[ExcludeFromCodeCoverage]
public class TextInputEvent
public class TextInputEvent : IEvent
{
public string Text { get; }

Expand Down

0 comments on commit 1ddf2b7

Please sign in to comment.