Skip to content

Commit

Permalink
Added support for SimpleInjector.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobpovar authored and phatboyg committed Nov 6, 2015
1 parent b21fbef commit 84c8c7a
Show file tree
Hide file tree
Showing 17 changed files with 511 additions and 44 deletions.
88 changes: 45 additions & 43 deletions .gitignore
@@ -1,43 +1,45 @@
build_output/*
build_artifacts/*
build_temp/*
*.suo
*.user
packages
*.dotCover

*.ncrunch*
.vs

.fake

src/logs/*

**/*.sln*
bin
obj
_ReSharper*

*.csproj.user
*.resharper.user
*.resharper
*.ReSharper
*.cache
*~
*.swp
*.bak
*.orig

NuGet.exe
packages

TestResult.xml
submit.xml
tests/*
SolutionVersion.cs
src/SolutionVersion.cs
tests
doc/build/*

# osx noise
.DS_Store
build_output/*
build_artifacts/*
build_temp/*
*.suo
*.user
packages
*.dotCover

*.ncrunch*
.vs

.fake

src/logs/*

**/*.sln*
bin
obj
_ReSharper*

*.csproj.user
*.resharper.user
*.resharper
*.ReSharper
*.cache
*~
*.swp
*.bak
*.orig

NuGet.exe
packages

TestResult.xml
submit.xml
tests/*
SolutionVersion.cs
src/SolutionVersion.cs
tests
doc/build/*

# osx noise
.DS_Store
*.DotSettings
/src/MassTransit.SimpleInjectorIntegration/MassTransit.SimpleInjectorIntegration.csproj.nuspec
Expand Up @@ -86,6 +86,14 @@
<HintPath>..\..\packages\Shouldly.2.6.0\lib\net40\Shouldly.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SimpleInjector, Version=3.1.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\..\packages\SimpleInjector.3.1.0\lib\net45\SimpleInjector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SimpleInjector.Extensions.ExecutionContextScoping, Version=3.1.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\..\packages\SimpleInjector.Extensions.ExecutionContextScoping.3.1.0\lib\net45\SimpleInjector.Extensions.ExecutionContextScoping.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="StructureMap, Version=3.1.6.191, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
<HintPath>..\..\packages\structuremap-signed.3.1.6.191\lib\net40\StructureMap.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -121,6 +129,7 @@
<Compile Include="Scenarios\SimpleConsumer.cs" />
<Compile Include="Scenarios\SimpleMessageClass.cs" />
<Compile Include="Scenarios\SimpleMessageInterface.cs" />
<Compile Include="SimpleInjector_Specs.cs" />
<Compile Include="StructureMap_Idiomatic.cs" />
<Compile Include="StructureMap_Specs.cs" />
<Compile Include="Unity_Specs.cs" />
Expand All @@ -142,6 +151,10 @@
<Project>{25A2A3C3-27D0-4C55-A9E9-0B82D6B6913F}</Project>
<Name>MassTransit.NinjectIntegration</Name>
</ProjectReference>
<ProjectReference Include="..\MassTransit.SimpleInjectorIntegration\MassTransit.SimpleInjectorIntegration.csproj">
<Project>{259e9f30-40ec-47b0-83ae-a2271ef3421d}</Project>
<Name>MassTransit.SimpleInjectorIntegration</Name>
</ProjectReference>
<ProjectReference Include="..\MassTransit.StructureMapIntegration\MassTransit.StructureMapIntegration.csproj">
<Project>{F5E67502-2B30-484C-88C3-97710291F5AA}</Project>
<Name>MassTransit.StructureMapIntegration</Name>
Expand Down
Expand Up @@ -22,7 +22,7 @@ public abstract class When_registering_a_consumer :
Given_a_service_bus_instance
{
[Test]
public async void Should_receive_using_the_first_consumer()
public async Task Should_receive_using_the_first_consumer()
{
const string name = "Joe";

Expand Down
@@ -0,0 +1,70 @@
namespace MassTransit.Containers.Tests
{
using MassTransit.Containers.Tests.Scenarios;
using MassTransit.Saga;
using MassTransit.SimpleInjectorIntegration;

using NUnit.Framework;

using SimpleInjector;
using SimpleInjector.Extensions.ExecutionContextScoping;

public class SimpleInjector_Consumer :
When_registering_a_consumer
{
[TearDown]
public void Close_container()
{
_container.Dispose();
}

readonly Container _container;

public SimpleInjector_Consumer()
{
_container = new Container();
_container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
_container.Register<SimpleConsumer>(Lifestyle.Scoped);
_container.Register<ISimpleConsumerDependency, SimpleConsumerDependency>(
Lifestyle.Scoped);
_container.Register<AnotherMessageConsumer, AnotherMessageConsumerImpl>(
Lifestyle.Scoped);
}

protected override void ConfigureInputQueueEndpoint(IReceiveEndpointConfigurator configurator)
{
configurator.LoadFrom(_container);
}
}


public class SimpleInjector_Saga :
When_registering_a_saga
{
[TestFixtureTearDown]
public void Close_container()
{
_container.Dispose();
}

readonly Container _container;

public SimpleInjector_Saga()
{
_container = new Container();
_container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
_container.Register(typeof(ISagaRepository<>), typeof(InMemorySagaRepository<>),
Lifestyle.Singleton);
}

protected override void ConfigureInputQueueEndpoint(IReceiveEndpointConfigurator configurator)
{
configurator.Saga<SimpleSaga>(_container);
}

protected override ISagaRepository<T> GetSagaRepository<T>()
{
return _container.GetInstance<ISagaRepository<T>>();
}
}
}
4 changes: 4 additions & 0 deletions src/Containers/MassTransit.Containers.Tests/app.config
Expand Up @@ -6,6 +6,10 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="SimpleInjector" publicKeyToken="984cb50dea722e99" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 2 additions & 0 deletions src/Containers/MassTransit.Containers.Tests/packages.config
Expand Up @@ -10,6 +10,8 @@
<package id="Ninject.Extensions.NamedScope" version="3.2.0.0" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="Shouldly" version="2.6.0" targetFramework="net45" />
<package id="SimpleInjector" version="3.1.0" targetFramework="net45" />
<package id="SimpleInjector.Extensions.ExecutionContextScoping" version="3.1.0" targetFramework="net45" />
<package id="structuremap-signed" version="3.1.6.191" targetFramework="net45" />
<package id="Unity" version="4.0.1" targetFramework="net45" />
</packages>
@@ -0,0 +1,42 @@
namespace MassTransit.SimpleInjectorIntegration
{
using System;
using System.Collections.Concurrent;

using SimpleInjector;

public static class ConsumerConfiguratorCache
{
static CachedConfigurator GetOrAdd(Type type)
{
return Cached.Instance.GetOrAdd(type, _ =>
(CachedConfigurator)Activator.CreateInstance(typeof(CachedConfigurator<>).MakeGenericType(type)));
}

public static void Configure(Type consumerType, IReceiveEndpointConfigurator configurator, Container container)
{
GetOrAdd(consumerType).Configure(configurator, container);
}

interface CachedConfigurator
{
void Configure(IReceiveEndpointConfigurator configurator, Container container);
}

class CachedConfigurator<T> :
CachedConfigurator
where T : class, IConsumer
{
public void Configure(IReceiveEndpointConfigurator configurator, Container container)
{
configurator.Consumer(new SimpleInjectorConsumerFactory<T>(container));
}
}

static class Cached
{
internal static readonly ConcurrentDictionary<Type, CachedConfigurator> Instance =
new ConcurrentDictionary<Type, CachedConfigurator>();
}
}
}
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{259E9F30-40EC-47B0-83AE-A2271EF3421D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MassTransit.SimpleInjectorIntegration</RootNamespace>
<AssemblyName>MassTransit.SimpleInjectorIntegration</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="SimpleInjector, Version=3.1.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\..\packages\SimpleInjector.3.1.0\lib\net45\SimpleInjector.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SimpleInjector.Extensions.ExecutionContextScoping, Version=3.1.0.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL">
<HintPath>..\..\packages\SimpleInjector.Extensions.ExecutionContextScoping.3.1.0\lib\net45\SimpleInjector.Extensions.ExecutionContextScoping.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\SolutionVersion.cs">
<Link>SolutionVersion.cs</Link>
</Compile>
<Compile Include="ConsumerConfiguratorCache.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SagaConfiguratorCache.cs" />
<Compile Include="SimpleInjectorConsumerFactory.cs" />
<Compile Include="SimpleInjectorExtensions.cs" />
<Compile Include="SimpleInjectorSagaRepository.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MassTransit\MassTransit.csproj">
<Project>{6EFD69FC-CBCC-4F85-AEE0-EFBA73F4D273}</Project>
<Name>MassTransit</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1 @@


0 comments on commit 84c8c7a

Please sign in to comment.