From 6712693db1d456a625bc580800f237abc73a74fc Mon Sep 17 00:00:00 2001 From: MCCshreyas Date: Sat, 10 Oct 2020 19:10:58 +0530 Subject: [PATCH] Removed exception types from EventPublishedContext and done with work of EventPublisherListener work. --- src/Eventify/EventPublishedContext.cs | 22 ++++++---------------- src/Eventify/EventPublishingContext.cs | 2 +- src/Eventify/Eventify.csproj | 2 +- src/Eventify/EventifyServiceExtensions.cs | 4 +++- src/Eventify/IEventPublisherListener.cs | 2 +- src/Eventify/InMemoryEventPublisher.cs | 2 +- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/Eventify/EventPublishedContext.cs b/src/Eventify/EventPublishedContext.cs index 853ceb6..2cb85f3 100644 --- a/src/Eventify/EventPublishedContext.cs +++ b/src/Eventify/EventPublishedContext.cs @@ -13,28 +13,18 @@ public class EventPublishedContext : EventPublishingContext /// /// Represents the does exception occurred while publishing event or not /// - public bool IsFaulted => EventExceptionList.Count != 0; + public bool IsFaulted => EventException != null; - /// - /// This will contain occurred exception information for further logging or processing - /// - public List EventExceptionList { get; } - - /// - /// Type of handler in which has been thrown-ed - /// - public List ExceptionHandlerTypeList { get; } + public Exception EventException { get; private set; } - internal EventPublishedContext(Guid eventId, string eventName, Type eventType) : base(eventId, eventName, eventType) + internal EventPublishedContext(Guid eventId, string eventName, Type eventType) + : base(eventId, eventName, eventType) { - EventExceptionList = new List(); - ExceptionHandlerTypeList = new List(); } - internal void SetException(Exception e, Type handlerExceptionType) + internal void SetException(Exception e) { - EventExceptionList.Add(e); - ExceptionHandlerTypeList.Add(handlerExceptionType); + EventException = e; } } } \ No newline at end of file diff --git a/src/Eventify/EventPublishingContext.cs b/src/Eventify/EventPublishingContext.cs index 918ce5a..f708ca2 100644 --- a/src/Eventify/EventPublishingContext.cs +++ b/src/Eventify/EventPublishingContext.cs @@ -9,7 +9,7 @@ namespace Eventify /// public class EventPublishingContext { - protected object _eventData; + private object _eventData; /// /// Id of currently published diff --git a/src/Eventify/Eventify.csproj b/src/Eventify/Eventify.csproj index e01065d..4a301a1 100644 --- a/src/Eventify/Eventify.csproj +++ b/src/Eventify/Eventify.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/Eventify/EventifyServiceExtensions.cs b/src/Eventify/EventifyServiceExtensions.cs index 6fb98b8..b371619 100644 --- a/src/Eventify/EventifyServiceExtensions.cs +++ b/src/Eventify/EventifyServiceExtensions.cs @@ -16,7 +16,8 @@ public static void AddEventify(this IServiceCollection services, params Assembly foreach (var assembly in assemblies) { - var classTypes = assembly.GetTypes().Select(t => t.GetTypeInfo()).Where(t => t.IsClass && !t.IsAbstract); + var classTypes = assembly.GetTypes().Select(t => t.GetTypeInfo()) + .Where(t => t.IsClass && !t.IsAbstract); foreach (var type in classTypes) { @@ -29,6 +30,7 @@ public static void AddEventify(this IServiceCollection services, params Assembly } } } + services.AddScoped(); } } diff --git a/src/Eventify/IEventPublisherListener.cs b/src/Eventify/IEventPublisherListener.cs index 9ff05c2..e14d151 100644 --- a/src/Eventify/IEventPublisherListener.cs +++ b/src/Eventify/IEventPublisherListener.cs @@ -1,7 +1,7 @@ namespace Eventify { /// - /// Contract for Event listeners + /// Contract for Event publisher listeners /// public interface IEventPublisherListener { diff --git a/src/Eventify/InMemoryEventPublisher.cs b/src/Eventify/InMemoryEventPublisher.cs index 2ded183..37dcf0e 100644 --- a/src/Eventify/InMemoryEventPublisher.cs +++ b/src/Eventify/InMemoryEventPublisher.cs @@ -56,7 +56,7 @@ public Task Publish(Event @event) } catch (Exception e) { - publishedContext.SetException(e, handler.GetType()); + publishedContext.SetException(e); publishedContext.SetEventData(eventPublishingContext.GetEventData()); } }