Skip to content

Commit

Permalink
Merge pull request #83 from marcwittke/release/6.0.0
Browse files Browse the repository at this point in the history
Release/6.0.0
  • Loading branch information
marcwittke authored Oct 8, 2019
2 parents 262ec8e + 470121e commit d815f78
Show file tree
Hide file tree
Showing 50 changed files with 224 additions and 373 deletions.
5 changes: 3 additions & 2 deletions src/abstractions/Backend.Fx/Backend.Fx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -36,7 +37,7 @@
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.8.16" />
<PackageReference Include="System.Linq.Queryable" Version="4.3.0" />
<PackageReference Include="System.Security.Principal" Version="4.3.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19324-01" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19324-01" PrivateAssets="All" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static void SeedDataForTenant(this IBackendFxApplication application, Te

foreach (var dataGeneratorTypeToRun in dataGeneratorTypesToRun)
{
application.Invoke(() =>
application.InvokeAsync(() =>
{
IDataGenerator dataGenerator = application
.CompositionRoot
Expand Down
147 changes: 0 additions & 147 deletions src/abstractions/Backend.Fx/Extensions/AsyncHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ public IDisposable BeginScope(IIdentity identity = null, TenantId tenantId = nul
return new MultipleDisposable(scope, scopeDurationLogger);
}

public void Run<TJob>() where TJob : class, IJob
public async Task RunAsync<TJob>() where TJob : class, IJob
{
var tenantIds = TenantIdService.GetActiveTenantIds();
foreach (var tenantId in tenantIds)
{
Invoke(() => CompositionRoot.GetInstance<TJob>().Run(), new SystemIdentity(), tenantId);
await InvokeAsync(() => CompositionRoot.GetInstance<TJob>().Run(), new SystemIdentity(), tenantId);
}
}

public void Run<TJob>(TenantId tenantId) where TJob : class, IJob
public async Task RunAsync<TJob>(TenantId tenantId) where TJob : class, IJob
{
Invoke(() => CompositionRoot.GetInstance<TJob>().Run(), new SystemIdentity(), tenantId);
await InvokeAsync(() => CompositionRoot.GetInstance<TJob>().Run(), new SystemIdentity(), tenantId);
}

public void Invoke(Action action, IIdentity identity, TenantId tenantId)
public async Task InvokeAsync(Action action, IIdentity identity, TenantId tenantId)
{
using (BeginScope(new SystemIdentity(), tenantId))
{
Expand All @@ -97,7 +97,7 @@ public void Invoke(Action action, IIdentity identity, TenantId tenantId)
{
unitOfWork.Begin();
action.Invoke();
unitOfWork.Complete();
await unitOfWork.CompleteAsync();
}
catch (TargetInvocationException ex)
{
Expand All @@ -122,7 +122,7 @@ public async Task InvokeAsync(Func<Task> awaitableAsyncAction, IIdentity identit
{
unitOfWork.Begin();
await awaitableAsyncAction.Invoke();
unitOfWork.Complete();
await unitOfWork.CompleteAsync();
}
catch (TargetInvocationException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public interface IBackendFxApplication : IDisposable

IDisposable BeginScope(IIdentity identity = null, TenantId tenantId = null);

void Invoke(Action action, IIdentity identity, TenantId tenantId);
Task InvokeAsync(Action action, IIdentity identity, TenantId tenantId);

Task InvokeAsync(Func<Task> awaitableAsyncAction, IIdentity identity, TenantId tenantId);

void Run<TJob>() where TJob : class, IJob;
Task RunAsync<TJob>() where TJob : class, IJob;

void Run<TJob>(TenantId tenantId) where TJob : class, IJob;
Task RunAsync<TJob>(TenantId tenantId) where TJob : class, IJob;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Backend.Fx.Patterns.EventAggregation.Domain
using System.Threading.Tasks;

namespace Backend.Fx.Patterns.EventAggregation.Domain
{
using System;
using System.Collections.Concurrent;
Expand All @@ -8,16 +10,16 @@ public class DomainEventAggregator : IDomainEventAggregator
{
private class HandleAction
{
public HandleAction(string domainEventName, string handlerTypeName, Action action)
public HandleAction(string domainEventName, string handlerTypeName, Func<Task> asyncAction)
{
DomainEventName = domainEventName;
HandlerTypeName = handlerTypeName;
Action = action;
AsyncAction = asyncAction;
}

public string DomainEventName { get; }
public string HandlerTypeName { get; }
public Action Action { get; }
public Func<Task> AsyncAction { get; }
}

private static readonly ILogger Logger = LogManager.Create<DomainEventAggregator>();
Expand All @@ -42,20 +44,20 @@ public void PublishDomainEvent<TDomainEvent>(TDomainEvent domainEvent) where TDo
HandleAction handleAction = new HandleAction (
typeof(TDomainEvent).Name,
injectedHandler.GetType().Name,
() => injectedHandler.Handle(domainEvent));
() => injectedHandler.HandleAsync(domainEvent));

_handleActions.Enqueue(handleAction);
Logger.Debug($"Invocation of {injectedHandler.GetType().Name} for domain event {typeof(TDomainEvent).Name} registered. It will be executed on completion of unit of work");
}
}

public void RaiseEvents()
public async Task RaiseEvents()
{
while (_handleActions.TryDequeue(out var handleAction))
{
try
{
handleAction.Action.Invoke();
await handleAction.AsyncAction.Invoke();
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Backend.Fx.Patterns.EventAggregation.Domain
using System.Threading.Tasks;

namespace Backend.Fx.Patterns.EventAggregation.Domain
{
/// <summary>
/// Channel events from multiple objects into a single object to simplify registration for clients.
Expand All @@ -7,6 +9,6 @@
public interface IDomainEventAggregator
{
void PublishDomainEvent<TDomainEvent>(TDomainEvent domainEvent) where TDomainEvent : IDomainEvent;
void RaiseEvents();
Task RaiseEvents();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace Backend.Fx.Patterns.EventAggregation.Domain
using System.Threading.Tasks;

namespace Backend.Fx.Patterns.EventAggregation.Domain
{
public interface IDomainEventHandler<in TDomainEvent> where TDomainEvent : IDomainEvent
{
void Handle(TDomainEvent domainEvent);
Task HandleAsync(TDomainEvent domainEvent);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
namespace Backend.Fx.Patterns.EventAggregation.Integration
using System.Threading.Tasks;

namespace Backend.Fx.Patterns.EventAggregation.Integration
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using DependencyInjection;
using Environment.Authentication;
using Logging;
Expand All @@ -27,7 +28,7 @@ protected EventBus(IBackendFxApplication application)
}

public abstract void Connect();
public abstract Task Publish(IIntegrationEvent integrationEvent);
public abstract void Publish(IIntegrationEvent integrationEvent);


/// <inheritdoc />
Expand Down Expand Up @@ -118,17 +119,18 @@ public void Unsubscribe<TEvent>(IIntegrationEventHandler<TEvent> handler) where
protected abstract void Subscribe(string eventName);
protected abstract void Unsubscribe(string eventName);

protected virtual async Task ProcessAsync(string eventName, EventProcessingContext context)
protected virtual void Process(string eventName, EventProcessingContext context)
{
Logger.Info($"Processing a {eventName} event");
if (_subscriptions.TryGetValue(eventName, out List<ISubscription> subscriptions))
{
foreach (var subscription in subscriptions)
{
await _application.InvokeAsync(
() => Task.Factory.StartNew(() => subscription.Process(eventName, context)),
new SystemIdentity(),
context.TenantId);
// offload work to thread pool
// fire and forget is okay, since IBackendFxApplication.InvokeAsync provides exception handling
Task.Run(()=>_application
.InvokeAsync(() => subscription.Process(eventName, context), new SystemIdentity(), context.TenantId)
.ContinueWith(t => Logger.Info($"Processed {eventName} event with status {t.Status}")));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Backend.Fx.Patterns.EventAggregation.Integration
{
using System.Collections.Concurrent;
using System.Threading.Tasks;

public interface IEventBusScope
{
Expand All @@ -12,7 +11,7 @@ public interface IEventBusScope
/// </summary>
/// <param name="integrationEvent"></param>
void Publish(IIntegrationEvent integrationEvent);
Task RaiseEvents();
void RaiseEvents();
}

public class EventBusScope : IEventBusScope
Expand All @@ -30,11 +29,11 @@ void IEventBusScope.Publish(IIntegrationEvent integrationEvent)
_integrationEvents.Enqueue(integrationEvent);
}

public async Task RaiseEvents()
public void RaiseEvents()
{
while (_integrationEvents.TryDequeue(out var integrationEvent))
{
await _eventBus.Publish(integrationEvent);
_eventBus.Publish(integrationEvent);
}
}
}
Expand Down
Loading

0 comments on commit d815f78

Please sign in to comment.