diff --git a/Luxoria.App/Luxoria.Modules/EventBus.cs b/Luxoria.App/Luxoria.Modules/EventBus.cs index 29f8357..b765467 100644 --- a/Luxoria.App/Luxoria.Modules/EventBus.cs +++ b/Luxoria.App/Luxoria.Modules/EventBus.cs @@ -12,7 +12,7 @@ public class EventBus : IEventBus /// Publishes an event to all subscribed handlers. /// Supports both synchronous and asynchronous execution. /// - public async Task Publish(TEvent @event) + public async Task Publish(TEvent @event) where TEvent : IEvent { if (EqualityComparer.Default.Equals(@event, default(TEvent))) { @@ -48,7 +48,7 @@ public async Task Publish(TEvent @event) /// /// Subscribes a synchronous handler to the specified event type. /// - public void Subscribe(Action handler) + public void Subscribe(Action handler) where TEvent : IEvent { if (handler == null) { @@ -67,7 +67,7 @@ public void Subscribe(Action handler) /// /// Subscribes an asynchronous handler to the specified event type. /// - public void Subscribe(Func asyncHandler) + public void Subscribe(Func asyncHandler) where TEvent : IEvent { if (asyncHandler == null) { @@ -86,7 +86,7 @@ public void Subscribe(Func asyncHandler) /// /// Unsubscribes a synchronous handler from the specified event type. /// - public void Unsubscribe(Action handler) + public void Unsubscribe(Action handler) where TEvent : IEvent { if (handler == null) { @@ -102,7 +102,7 @@ public void Unsubscribe(Action handler) /// /// Unsubscribes an asynchronous handler from the specified event type. /// - public void Unsubscribe(Func asyncHandler) + public void Unsubscribe(Func asyncHandler) where TEvent : IEvent { if (asyncHandler == null) { diff --git a/Luxoria.App/Luxoria.Modules/Interfaces/IEvent.cs b/Luxoria.App/Luxoria.Modules/Interfaces/IEvent.cs new file mode 100644 index 0000000..2c1c6cb --- /dev/null +++ b/Luxoria.App/Luxoria.Modules/Interfaces/IEvent.cs @@ -0,0 +1,8 @@ +namespace Luxoria.Modules.Interfaces; + +/// +/// Interface that represents an event that can be published and subscribed to +/// +public interface IEvent +{ +} diff --git a/Luxoria.App/Luxoria.Modules/Interfaces/IEventBus.cs b/Luxoria.App/Luxoria.Modules/Interfaces/IEventBus.cs index d4e2d59..e583288 100644 --- a/Luxoria.App/Luxoria.Modules/Interfaces/IEventBus.cs +++ b/Luxoria.App/Luxoria.Modules/Interfaces/IEventBus.cs @@ -3,18 +3,18 @@ public interface IEventBus { // Publishes an event to all subscribed handlers, supporting both async and sync. - Task Publish(TEvent @event); + Task Publish(TEvent @event) where TEvent : IEvent; // Subscribes a synchronous handler to the event type. - void Subscribe(Action handler); + void Subscribe(Action handler) where TEvent : IEvent; // Subscribes an asynchronous handler to the event type. - void Subscribe(Func asyncHandler); + void Subscribe(Func asyncHandler) where TEvent : IEvent; // Unsubscribes a synchronous handler from the event type. - void Unsubscribe(Action handler); + void Unsubscribe(Action handler) where TEvent : IEvent; // Unsubscribes an asynchronous handler from the event type. - void Unsubscribe(Func asyncHandler); + void Unsubscribe(Func asyncHandler) where TEvent : IEvent; } } diff --git a/Luxoria.App/Luxoria.Modules/Models/Events/CollectionUpdatedEvent.cs b/Luxoria.App/Luxoria.Modules/Models/Events/CollectionUpdatedEvent.cs index 1ce8b88..e093ae2 100644 --- a/Luxoria.App/Luxoria.Modules/Models/Events/CollectionUpdatedEvent.cs +++ b/Luxoria.App/Luxoria.Modules/Models/Events/CollectionUpdatedEvent.cs @@ -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 { /// /// Collection name diff --git a/Luxoria.App/Luxoria.Modules/Models/Events/ImageUpdatedEvent.cs b/Luxoria.App/Luxoria.Modules/Models/Events/ImageUpdatedEvent.cs index 15968a5..d439249 100644 --- a/Luxoria.App/Luxoria.Modules/Models/Events/ImageUpdatedEvent.cs +++ b/Luxoria.App/Luxoria.Modules/Models/Events/ImageUpdatedEvent.cs @@ -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; } diff --git a/Luxoria.App/Luxoria.Modules/Models/Events/LogEvent.cs b/Luxoria.App/Luxoria.Modules/Models/Events/LogEvent.cs index 2218164..d9d2760 100644 --- a/Luxoria.App/Luxoria.Modules/Models/Events/LogEvent.cs +++ b/Luxoria.App/Luxoria.Modules/Models/Events/LogEvent.cs @@ -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; } diff --git a/Luxoria.App/Luxoria.Modules/Models/Events/OpenCollectionEvent.cs b/Luxoria.App/Luxoria.Modules/Models/Events/OpenCollectionEvent.cs index 56b50f3..2d8bc1d 100644 --- a/Luxoria.App/Luxoria.Modules/Models/Events/OpenCollectionEvent.cs +++ b/Luxoria.App/Luxoria.Modules/Models/Events/OpenCollectionEvent.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.CodeAnalysis; +using Luxoria.Modules.Interfaces; +using System.Diagnostics.CodeAnalysis; namespace Luxoria.Modules.Models.Events; @@ -6,7 +7,7 @@ namespace Luxoria.Modules.Models.Events; /// Represents an event triggered when a collection is opened. /// [ExcludeFromCodeCoverage] -public class OpenCollectionEvent +public class OpenCollectionEvent : IEvent { // *** Properties *** diff --git a/Luxoria.App/Luxoria.Modules/Models/Events/TextInputEvent.cs b/Luxoria.App/Luxoria.Modules/Models/Events/TextInputEvent.cs index e840539..eda19cc 100644 --- a/Luxoria.App/Luxoria.Modules/Models/Events/TextInputEvent.cs +++ b/Luxoria.App/Luxoria.Modules/Models/Events/TextInputEvent.cs @@ -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; }