Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus committed Jun 26, 2018
2 parents 4f2c3ee + fd830bb commit 0bba057
Show file tree
Hide file tree
Showing 32 changed files with 933 additions and 64 deletions.
20 changes: 18 additions & 2 deletions EventFlow.sln
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.Autofac.Tests", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNetCore", "AspNetCore", "{3A34F6A2-64B0-4730-A0EB-D324BC755538}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventFlow.AspNetCore", "Source\EventFlow.AspNetCore\EventFlow.AspNetCore.csproj", "{9D57E096-AA8E-40E5-A1CC-32C07B425850}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.AspNetCore", "Source\EventFlow.AspNetCore\EventFlow.AspNetCore.csproj", "{9D57E096-AA8E-40E5-A1CC-32C07B425850}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventFlow.AspNetCore.Tests", "Source\EventFlow.AspNetCore.Tests\EventFlow.AspNetCore.Tests.csproj", "{C16B0B27-6E6C-439C-8419-488B2D4D798F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.AspNetCore.Tests", "Source\EventFlow.AspNetCore.Tests\EventFlow.AspNetCore.Tests.csproj", "{C16B0B27-6E6C-439C-8419-488B2D4D798F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.DependencyInjection", "Source\EventFlow.DependencyInjection\EventFlow.DependencyInjection.csproj", "{7870461F-BA5B-4198-A85E-03BA555198AD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.DependencyInjection.Tests", "Source\EventFlow.DependencyInjection.Tests\EventFlow.DependencyInjection.Tests.csproj", "{28CA7AD8-6A73-454C-ABF4-26B24D986C85}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DependencyInjection", "DependencyInjection", "{E2DD51BC-974B-4526-961B-825913911FFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -187,6 +193,14 @@ Global
{C16B0B27-6E6C-439C-8419-488B2D4D798F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C16B0B27-6E6C-439C-8419-488B2D4D798F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C16B0B27-6E6C-439C-8419-488B2D4D798F}.Release|Any CPU.Build.0 = Release|Any CPU
{7870461F-BA5B-4198-A85E-03BA555198AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7870461F-BA5B-4198-A85E-03BA555198AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7870461F-BA5B-4198-A85E-03BA555198AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7870461F-BA5B-4198-A85E-03BA555198AD}.Release|Any CPU.Build.0 = Release|Any CPU
{28CA7AD8-6A73-454C-ABF4-26B24D986C85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28CA7AD8-6A73-454C-ABF4-26B24D986C85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28CA7AD8-6A73-454C-ABF4-26B24D986C85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28CA7AD8-6A73-454C-ABF4-26B24D986C85}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -217,6 +231,8 @@ Global
{EFDD4B74-E69A-4F4F-80F4-DC8F32CD76A5} = {980EEDAA-1FEF-4D7C-8811-5EF1D9729773}
{9D57E096-AA8E-40E5-A1CC-32C07B425850} = {3A34F6A2-64B0-4730-A0EB-D324BC755538}
{C16B0B27-6E6C-439C-8419-488B2D4D798F} = {3A34F6A2-64B0-4730-A0EB-D324BC755538}
{7870461F-BA5B-4198-A85E-03BA555198AD} = {E2DD51BC-974B-4526-961B-825913911FFB}
{28CA7AD8-6A73-454C-ABF4-26B24D986C85} = {E2DD51BC-974B-4526-961B-825913911FFB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17607E2C-4E8E-45A2-85BD-0A5808E1C0F3}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ to the documentation.
* In-memory - only for test
* Files - only for test
* Microsoft SQL Server
* EventStore - [home page](https://geteventstore.com/)
* EventStore - [home page](https://eventstore.org/)
* [**Subscribers:**](http://docs.geteventflow.net/Subscribers.html)
Listeners that act on specific domain events. Useful if an specific action
needs to be triggered after a domain event has been committed.
Expand Down
26 changes: 25 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
### New in 0.60 (not released yet)
### New in 0.61 (not released yet)

* New: Support for `Microsoft.Extensions.DependencyInjection` (`IServiceProvider`
and `IServiceCollection`) using the `EventFlow.DependencyInjection` NuGet package.

Add it to your ASP.NET Core 2.0 application:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddEventFlow(o => o.AddDefaults(MyDomainAssembly));
}
```
Or use it explicitly:
```csharp
EventFlowOptions.New.
.UseServiceCollection()
...
.CreateServiceProvider();
```
* New: Package `EventFlow.Autofac` now references Autofac 3.5.2 for .NET
framework 4.5.1 (down from Autofac v4.5.0)
* Fixed: Constructor injection of scoped instances into query handlers

### New in 0.60.3490 (released 2018-06-18)

* New: Implemented optimistic concurrency checks for MSSQL, SQLite and
Elasticsearch read models
Expand Down
1 change: 1 addition & 0 deletions Source/EventFlow.AspNetCore/EventFlow.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using EventFlow.AspNetCore.ServiceProvider;
using EventFlow.Extensions;
using Microsoft.Extensions.Hosting;

namespace EventFlow.AspNetCore.Extensions
{
Expand All @@ -34,7 +36,11 @@ public static IEventFlowOptions AddAspNetCoreMetadataProviders(
this IEventFlowOptions eventFlowOptions)
{
return eventFlowOptions
.RegisterServices(sr => sr.Register(typeof(IHttpContextAccessor), typeof(HttpContextAccessor), Lifetime.Singleton))
.RegisterServices(sr =>
{
sr.Register(typeof(IHttpContextAccessor), typeof(HttpContextAccessor), Lifetime.Singleton);
sr.Register(typeof(IHostedService), typeof(HostedBootstrapper), Lifetime.Singleton);
})
.AddMetadataProviders(EventFlowAspNetCore.Assembly);
}
}
Expand Down
56 changes: 56 additions & 0 deletions Source/EventFlow.AspNetCore/ServiceProvider/HostedBootstrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// The MIT License (MIT)
//
// Copyright (c) 2015-2018 Rasmus Mikkelsen
// Copyright (c) 2015-2018 eBay Software Foundation
// https://github.com/eventflow/EventFlow
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System.Threading;
using System.Threading.Tasks;
using EventFlow.Configuration.Bootstraps;
using Microsoft.Extensions.Hosting;

namespace EventFlow.AspNetCore.ServiceProvider
{
/// <summary>
/// Ensures that the <see cref="Bootstrapper" /> is run in an ASP.NET Core
/// environment when EventFlow is configured into an existing ServiceCollection
/// instance and <see cref="CreateResolver" /> is not used.
/// </summary>
// ReSharper disable once ClassNeverInstantiated.Local
class HostedBootstrapper : IHostedService
{
private readonly IBootstrapper _bootstrapper;

public HostedBootstrapper(IBootstrapper bootstrapper)
{
_bootstrapper = bootstrapper;
}

public Task StartAsync(CancellationToken cancellationToken)
{
return _bootstrapper.StartAsync(cancellationToken);
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System.Threading.Tasks;
using Autofac;
using EventFlow.Autofac.Extensions;
using EventFlow.Configuration;
using EventFlow.Extensions;
using EventFlow.TestHelpers;
using EventFlow.TestHelpers.Aggregates.Queries;
using EventFlow.TestHelpers.Suites;
using NUnit.Framework;

Expand All @@ -34,14 +38,24 @@ public class AutofacServiceRegistrationIntegrationTests : IntegrationTestSuiteFo
{
protected override IEventFlowOptions Options(IEventFlowOptions eventFlowOptions)
{
var builder = new ContainerBuilder();
builder.RegisterType<DbContext>().As<IDbContext>().InstancePerLifetimeScope();

return base.Options(eventFlowOptions
.UseAutofacContainerBuilder());
.UseAutofacContainerBuilder(builder))
.AddQueryHandler<DbContextQueryHandler, DbContextQuery, string>();
}

protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
{
return eventFlowOptions
.CreateResolver();
}

[Test]
public override Task QueryingUsesScopedDbContext()
{
return base.QueryingUsesScopedDbContext();
}
}
}
8 changes: 7 additions & 1 deletion Source/EventFlow.Autofac/EventFlow.Autofac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
<NeutralLanguage>en-US</NeutralLanguage>
<PackageReleaseNotes>UPDATED BY BUILD</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<PackageReference Include="Autofac" Version="3.5.2" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.6'">
<PackageReference Include="Autofac" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Autofac" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Autofac;
using EventFlow.Configuration;
using EventFlow.Configuration.Bootstraps;
using EventFlow.Configuration.Decorators;
using EventFlow.Core;
using EventFlow.Core.IoC;
using EventFlow.Extensions;

namespace EventFlow.Autofac.Registrations
{
internal class AutofacServiceRegistration : ServiceRegistration, IServiceRegistration
internal class AutofacServiceRegistration : IServiceRegistration
{
private readonly ContainerBuilder _containerBuilder;
private readonly DecoratorService _decoratorService = new DecoratorService();
Expand All @@ -49,6 +44,7 @@ public AutofacServiceRegistration(ContainerBuilder containerBuilder)
_containerBuilder.RegisterType<AutofacResolver>().As<IResolver>();
_containerBuilder.Register(c => new AutofacScopeResolver(c.Resolve<ILifetimeScope>().BeginLifetimeScope())).As<IScopeResolver>();
_containerBuilder.Register<IDecoratorService>(_ => _decoratorService).SingleInstance();
_containerBuilder.RegisterType<Bootstrapper>().As<IBootstrapper>().SingleInstance();
}

public void Register<TService, TImplementation>(
Expand Down Expand Up @@ -189,25 +185,16 @@ public IRootResolver CreateResolver(bool validateRegistrations)

public class AutofacStartable : IStartable
{
private readonly IReadOnlyCollection<IBootstrap> _bootstraps;
private readonly IBootstrapper _bootstrapper;

public AutofacStartable(
IEnumerable<IBootstrap> bootstraps)
public AutofacStartable(IBootstrapper bootstrapper)
{
_bootstraps = OrderBootstraps(bootstraps);
_bootstrapper = bootstrapper;
}

public void Start()
{
using (var a = AsyncHelper.Wait)
{
a.Run(StartAsync(CancellationToken.None));
}
}

private Task StartAsync(CancellationToken cancellationToken)
{
return Task.WhenAll(_bootstraps.Select(b => b.BootAsync(cancellationToken)));
_bootstrapper.Start();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.18" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.18" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EventFlow.DependencyInjection\EventFlow.DependencyInjection.csproj" />
<ProjectReference Include="..\EventFlow.TestHelpers\EventFlow.TestHelpers.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// The MIT License (MIT)
//
// Copyright (c) 2015-2018 Rasmus Mikkelsen
// Copyright (c) 2015-2018 eBay Software Foundation
// https://github.com/eventflow/EventFlow
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System.Threading.Tasks;
using EventFlow.Configuration;
using EventFlow.DependencyInjection.Extensions;
using EventFlow.Extensions;
using EventFlow.TestHelpers;
using EventFlow.TestHelpers.Aggregates.Queries;
using EventFlow.TestHelpers.Suites;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

namespace EventFlow.DependencyInjection.Tests.IntegrationTests
{
[Category(Categories.Integration)]
public class ServiceCollectionServiceRegistrationIntegrationTests : IntegrationTestSuiteForServiceRegistration
{
protected override IEventFlowOptions Options(IEventFlowOptions eventFlowOptions)
{
var serviceCollection = new ServiceCollection();

serviceCollection.AddScoped<IDbContext, DbContext>();

return base.Options(eventFlowOptions
.UseServiceCollection(serviceCollection))
.AddQueryHandler<DbContextQueryHandler, DbContextQuery, string>();
}

protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
{
return eventFlowOptions
.CreateResolver();
}

[Test]
public override Task QueryingUsesScopedDbContext()
{
return base.QueryingUsesScopedDbContext();
}
}
}
Loading

0 comments on commit 0bba057

Please sign in to comment.