Skip to content
This repository was archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
eventbus dispose fix, default event bus removed, uow outer filter cop…
Browse files Browse the repository at this point in the history
…y added
  • Loading branch information
trendyol-bot committed Mar 1, 2017
1 parent 03ca29f commit 87a7a2f
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 70 deletions.
3 changes: 2 additions & 1 deletion src/Stove/Bootstrapping/StoveKernelBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;

using Autofac;
using Autofac.Extras.IocManager;

using Stove.BackgroundJobs;
Expand Down Expand Up @@ -68,7 +69,7 @@ private void ConfigureEventBus()
Type[] genericArgs = @interface.GetGenericArguments();
if (genericArgs.Length == 1)
{
_eventBus.Register(genericArgs[0], new IocHandlerFactory(Resolver.Resolve<IScopeResolver>().BeginScope(), impl));
_eventBus.Register(genericArgs[0], new IocHandlerFactory(Resolver.Resolve<IScopeResolver>(), impl));
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/Stove/Domain/Uow/UnitOfWorkManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Transactions;
using System.Linq;
using System.Transactions;

using Autofac.Extras.IocManager;

Expand Down Expand Up @@ -45,7 +46,9 @@ public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options)

options.FillDefaultsForNonProvidedOptions(_defaultOptions);

if (options.Scope == TransactionScopeOption.Required && _currentUnitOfWorkProvider.Current != null)
IUnitOfWork outerUow = _currentUnitOfWorkProvider.Current;

if (options.Scope == TransactionScopeOption.Required && outerUow != null)
{
return new InnerUnitOfWorkCompleteHandle();
}
Expand All @@ -58,6 +61,12 @@ public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options)

uow.Disposed += (sender, args) => { _childScope.Dispose(); };

//Inherit filters from outer UOW
if (outerUow != null)
{
options.FillOuterUowFiltersForNonProvidedOptions(outerUow.Filters.ToList());
}

uow.Begin(options);

_currentUnitOfWorkProvider.Current = uow;
Expand Down
14 changes: 14 additions & 0 deletions src/Stove/Domain/Uow/UnitOfWorkOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Transactions;

namespace Stove.Domain.Uow
Expand Down Expand Up @@ -75,5 +76,18 @@ internal void FillDefaultsForNonProvidedOptions(IUnitOfWorkDefaultOptions defaul
IsolationLevel = defaultOptions.IsolationLevel.Value;
}
}

internal void FillOuterUowFiltersForNonProvidedOptions(List<DataFilterConfiguration> filterOverrides)
{
foreach (var filterOverride in filterOverrides)
{
if (FilterOverrides.Any(fo => fo.FilterName == filterOverride.FilterName))
{
continue;
}

FilterOverrides.Add(filterOverride);
}
}
}
}
5 changes: 0 additions & 5 deletions src/Stove/Events/Bus/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public EventBus()
Logger = NullLogger.Instance;
}

/// <summary>
/// Gets the default <see cref="EventBus" /> instance.
/// </summary>
public static EventBus Default { get; } = new EventBus();

/// <summary>
/// Reference to the Logger.
/// </summary>
Expand Down
69 changes: 28 additions & 41 deletions src/Stove/Events/Bus/IEventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,154 +7,144 @@
namespace Stove.Events.Bus
{
/// <summary>
/// Defines interface of the event bus.
/// Defines interface of the event bus.
/// </summary>
public interface IEventBus
{
#region Register

/// <summary>
/// Registers to an event.
/// Given action is called for all event occurrences.
/// Registers to an event.
/// Given action is called for all event occurrences.
/// </summary>
/// <param name="action">Action to handle events</param>
/// <typeparam name="TEventData">Event type</typeparam>
IDisposable Register<TEventData>(Action<TEventData> action) where TEventData : IEventData;

/// <summary>
/// Registers to an event.
/// Same (given) instance of the handler is used for all event occurrences.
/// Registers to an event.
/// Same (given) instance of the handler is used for all event occurrences.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="handler">Object to handle the event</param>
IDisposable Register<TEventData>(IEventHandler<TEventData> handler) where TEventData : IEventData;

/// <summary>
/// Registers to an event.
/// A new instance of <see cref="THandler"/> object is created for every event occurrence.
/// Registers to an event.
/// A new instance of <see cref="THandler" /> object is created for every event occurrence.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <typeparam name="THandler">Type of the event handler</typeparam>
IDisposable Register<TEventData, THandler>() where TEventData : IEventData where THandler : IEventHandler<TEventData>, new();

/// <summary>
/// Registers to an event.
/// Same (given) instance of the handler is used for all event occurrences.
/// Registers to an event.
/// Same (given) instance of the handler is used for all event occurrences.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="handler">Object to handle the event</param>
IDisposable Register(Type eventType, IEventHandler handler);

/// <summary>
/// Registers to an event.
/// Given factory is used to create/release handlers
/// Registers to an event.
/// Given factory is used to create/release handlers
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="handlerFactory">A factory to create/release handlers</param>
IDisposable Register<TEventData>(IEventHandlerFactory handlerFactory) where TEventData : IEventData;

/// <summary>
/// Registers to an event.
/// Registers to an event.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="handlerFactory">A factory to create/release handlers</param>
IDisposable Register(Type eventType, IEventHandlerFactory handlerFactory);

#endregion

#region Unregister

/// <summary>
/// Unregisters from an event.
/// Unregisters from an event.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="action"></param>
void Unregister<TEventData>(Action<TEventData> action) where TEventData : IEventData;

/// <summary>
/// Unregisters from an event.
/// Unregisters from an event.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="handler">Handler object that is registered before</param>
void Unregister<TEventData>(IEventHandler<TEventData> handler) where TEventData : IEventData;

/// <summary>
/// Unregisters from an event.
/// Unregisters from an event.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="handler">Handler object that is registered before</param>
void Unregister(Type eventType, IEventHandler handler);

/// <summary>
/// Unregisters from an event.
/// Unregisters from an event.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="factory">Factory object that is registered before</param>
void Unregister<TEventData>(IEventHandlerFactory factory) where TEventData : IEventData;

/// <summary>
/// Unregisters from an event.
/// Unregisters from an event.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="factory">Factory object that is registered before</param>
void Unregister(Type eventType, IEventHandlerFactory factory);

/// <summary>
/// Unregisters all event handlers of given event type.
/// Unregisters all event handlers of given event type.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
void UnregisterAll<TEventData>() where TEventData : IEventData;

/// <summary>
/// Unregisters all event handlers of given event type.
/// Unregisters all event handlers of given event type.
/// </summary>
/// <param name="eventType">Event type</param>
void UnregisterAll(Type eventType);

#endregion

#region Trigger

/// <summary>
/// Triggers an event.
/// Triggers an event.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="eventData">Related data for the event</param>
void Trigger<TEventData>(TEventData eventData) where TEventData : IEventData;

/// <summary>
/// Triggers an event.
/// Triggers an event.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="eventSource">The object which triggers the event</param>
/// <param name="eventData">Related data for the event</param>
void Trigger<TEventData>(object eventSource, TEventData eventData) where TEventData : IEventData;

/// <summary>
/// Triggers an event.
/// Triggers an event.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="eventData">Related data for the event</param>
void Trigger(Type eventType, IEventData eventData);

/// <summary>
/// Triggers an event.
/// Triggers an event.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="eventSource">The object which triggers the event</param>
/// <param name="eventData">Related data for the event</param>
void Trigger(Type eventType, object eventSource, IEventData eventData);

/// <summary>
/// Triggers an event asynchronously.
/// Triggers an event asynchronously.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="eventData">Related data for the event</param>
/// <returns>The task to handle async operation</returns>
Task TriggerAsync<TEventData>(TEventData eventData) where TEventData : IEventData;

/// <summary>
/// Triggers an event asynchronously.
/// Triggers an event asynchronously.
/// </summary>
/// <typeparam name="TEventData">Event type</typeparam>
/// <param name="eventSource">The object which triggers the event</param>
Expand All @@ -163,23 +153,20 @@ public interface IEventBus
Task TriggerAsync<TEventData>(object eventSource, TEventData eventData) where TEventData : IEventData;

/// <summary>
/// Triggers an event asynchronously.
/// Triggers an event asynchronously.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="eventData">Related data for the event</param>
/// <returns>The task to handle async operation</returns>
Task TriggerAsync(Type eventType, IEventData eventData);

/// <summary>
/// Triggers an event asynchronously.
/// Triggers an event asynchronously.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="eventSource">The object which triggers the event</param>
/// <param name="eventData">Related data for the event</param>
/// <returns>The task to handle async operation</returns>
Task TriggerAsync(Type eventType, object eventSource, IEventData eventData);


#endregion
}
}
}
14 changes: 1 addition & 13 deletions src/Stove/StoveCoreRegistrationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ public static IIocBuilder UseStoveDefaultConnectionStringResolver([NotNull] this
return builder;
}

/// <summary>
/// Uses the stove default event bus.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns></returns>
[NotNull]
public static IIocBuilder UseStoveDefaultEventBus([NotNull] this IIocBuilder builder)
{
builder.RegisterServices(r => r.Register<IEventBus>(context => EventBus.Default));
return builder;
}

/// <summary>
/// Uses the stove event bus.
/// </summary>
Expand All @@ -100,7 +88,7 @@ public static IIocBuilder UseStoveDefaultEventBus([NotNull] this IIocBuilder bui
[NotNull]
public static IIocBuilder UseStoveEventBus([NotNull] this IIocBuilder builder)
{
builder.RegisterServices(r => r.Register<IEventBus, EventBus>());
builder.RegisterServices(r => r.Register<IEventBus, EventBus>(Lifetime.Singleton));
return builder;
}

Expand Down
2 changes: 1 addition & 1 deletion test/Stove.Demo.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static void Main(string[] args)
.UseStoveEntityFramework()
.UseStoveDapper()
.UseStoveMapster()
.UseStoveDefaultEventBus()
.UseStoveEventBus()
.UseStoveDbContextEfTransactionStrategy()
.UseStoveTypedConnectionStringResolver()
.UseStoveNLog()
Expand Down
7 changes: 4 additions & 3 deletions test/Stove.Mapster.Tests/Stove.Mapster.Tests.xproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>7182fae3-631d-4485-af40-69d60a8bd8b7</ProjectGuid>
Expand All @@ -13,9 +12,11 @@
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>
7 changes: 4 additions & 3 deletions test/Stove.RabbitMQ.Tests/Stove.RabbitMQ.Tests.xproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>f024076f-a7aa-4b54-9f01-d3691a8bc988</ProjectGuid>
Expand All @@ -13,9 +12,11 @@
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>
Loading

0 comments on commit 87a7a2f

Please sign in to comment.