Skip to content

Commit

Permalink
almost done with structuremap integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mookid8000 committed Jul 27, 2015
1 parent 4ed081b commit c5e0b1e
Show file tree
Hide file tree
Showing 34 changed files with 21,268 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Rebus.StructureMap.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Rebus.StructureMap.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Rebus.StructureMap.Tests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("34446594-3678-49ac-a8b0-3575977348ff")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
82 changes: 82 additions & 0 deletions Rebus.StructureMap.Tests/Rebus.StructureMap.Tests.csproj
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.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>{230D2336-DA75-4B5E-B139-00AE3DD28B8F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Rebus.StructureMap.Tests</RootNamespace>
<AssemblyName>Rebus.StructureMap.Tests</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="nunit.framework">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="StructureMap">
<HintPath>..\packages\structuremap.3.1.6.186\lib\net40\StructureMap.dll</HintPath>
</Reference>
<Reference Include="StructureMap.Net4">
<HintPath>..\packages\structuremap.3.1.6.186\lib\net40\StructureMap.Net4.dll</HintPath>
</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="StructureMapContainerAdapterFactory.cs" />
<Compile Include="StructureMapContainerTests.cs" />
<Compile Include="StructureMapRealContainerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Rebus.StructureMap\Rebus.StructureMap.csproj">
<Project>{45BB02AA-0FA7-4FDD-B210-6C62BE42058A}</Project>
<Name>Rebus.StructureMap</Name>
</ProjectReference>
<ProjectReference Include="..\Rebus.Tests\Rebus.Tests.csproj">
<Project>{959C65AB-D21A-4582-BC4F-06D1425FF274}</Project>
<Name>Rebus.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\Rebus\Rebus.csproj">
<Project>{7D7B7B36-6298-4E85-9A0E-1B415C5B9D12}</Project>
<Name>Rebus</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>
42 changes: 42 additions & 0 deletions Rebus.StructureMap.Tests/StructureMapContainerAdapterFactory.cs
@@ -0,0 +1,42 @@
using System;
using System.Linq;
using Rebus.Activation;
using Rebus.Handlers;
using Rebus.Tests.Contracts.Activation;
using StructureMap;

namespace Rebus.StructureMap.Tests
{
public class CastleWindsorContainerAdapterFactory : IContainerAdapterFactory
{
readonly IContainer _container = new Container();

public IHandlerActivator GetActivator()
{
return new StructureMapContainerAdapter(_container);
}

public void RegisterHandlerType<THandler>() where THandler : class, IHandleMessages
{
_container.Configure(c =>
{
foreach (var handler in GetHandlerInterfaces(typeof (THandler)))
{
c.For(handler).Use(typeof (THandler)).Transient();
}
});
}

public void CleanUp()
{
_container.Dispose();
}

Type[] GetHandlerInterfaces(Type type)
{
return type.GetInterfaces()
.Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IHandleMessages<>))
.ToArray();
}
}
}
10 changes: 10 additions & 0 deletions Rebus.StructureMap.Tests/StructureMapContainerTests.cs
@@ -0,0 +1,10 @@
using NUnit.Framework;
using Rebus.Tests.Contracts.Activation;

namespace Rebus.StructureMap.Tests
{
[TestFixture]
public class StructureMapContainerTests : ContainerTests<CastleWindsorContainerAdapterFactory>
{
}
}
10 changes: 10 additions & 0 deletions Rebus.StructureMap.Tests/StructureMapRealContainerTests.cs
@@ -0,0 +1,10 @@
using NUnit.Framework;
using Rebus.Tests.Contracts.Activation;

namespace Rebus.StructureMap.Tests
{
[TestFixture]
public class StructureMapRealContainerTests : RealContainerTests<CastleWindsorContainerAdapterFactory>
{
}
}
5 changes: 5 additions & 0 deletions Rebus.StructureMap.Tests/packages.config
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="structuremap" version="3.1.6.186" targetFramework="net45" />
</packages>
36 changes: 36 additions & 0 deletions Rebus.StructureMap/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Rebus.StructureMap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Rebus.StructureMap")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d55faf57-490e-4b7d-8f91-b1214e2d074c")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
71 changes: 71 additions & 0 deletions Rebus.StructureMap/Rebus.StructureMap.csproj
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.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>{45BB02AA-0FA7-4FDD-B210-6C62BE42058A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Rebus.StructureMap</RootNamespace>
<AssemblyName>Rebus.StructureMap</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>
<DocumentationFile>bin\Release\Rebus.StructureMap.XML</DocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="StructureMap">
<HintPath>..\packages\structuremap.3.1.6.186\lib\net40\StructureMap.dll</HintPath>
</Reference>
<Reference Include="StructureMap.Net4">
<HintPath>..\packages\structuremap.3.1.6.186\lib\net40\StructureMap.Net4.dll</HintPath>
</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="StructureMapContainerAdapter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Rebus.StructureMap.nuspec" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Rebus\Rebus.csproj">
<Project>{7D7B7B36-6298-4E85-9A0E-1B415C5B9D12}</Project>
<Name>Rebus</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>
24 changes: 24 additions & 0 deletions Rebus.StructureMap/Rebus.StructureMap.nuspec
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>Rebus.StructureMap</id>
<version>$version$</version>
<title>Rebus.StructureMap</title>
<authors>mookid8000</authors>
<owners>mookid8000</owners>
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
<projectUrl>http://mookid.dk/oncode/rebus</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>StructureMap container adapter for Rebus</description>
<copyright>Copyright 2015</copyright>
<tags>rebus ioc structuremap</tags>
<iconUrl>https://github.com/mookid8000/Rebus/raw/master/artwork/logo200x200-transparent.png</iconUrl>
<dependencies>
<dependency id="Rebus" version="[2, 3)" />
</dependencies>
</metadata>
<files>
<file src="bin\Release\Rebus.CastleWindsor.dll" target="lib\NET45" />
<file src="bin\Release\Rebus.CastleWindsor.xml" target="lib\NET45" />
</files>
</package>
43 changes: 43 additions & 0 deletions Rebus.StructureMap/StructureMapContainerAdapter.cs
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Rebus.Activation;
using Rebus.Bus;
using Rebus.Handlers;
using Rebus.Pipeline;
using Rebus.Transport;
using StructureMap;

namespace Rebus.StructureMap
{
/// <summary>
/// Implementation of <see cref="IContainerAdapter"/> that uses StructureMap to do its thing
/// </summary>
public class StructureMapContainerAdapter : IContainerAdapter
{
readonly IContainer _container;

/// <summary>
/// Constructs the container adapter
/// </summary>
public StructureMapContainerAdapter(IContainer container)
{
_container = container;
}

public async Task<IEnumerable<IHandleMessages<TMessage>>> GetHandlers<TMessage>(TMessage message, ITransactionContext transactionContext)
{
return _container.GetAllInstances<IHandleMessages<TMessage>>();
}

public void SetBus(IBus bus)
{
_container.Configure(x =>
{
x.For<IBus>().Singleton().Add(bus);
x.For<IMessageContext>().Transient().Use(() => MessageContext.Current);
});
}
}
}
4 changes: 4 additions & 0 deletions Rebus.StructureMap/packages.config
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="structuremap" version="3.1.6.186" targetFramework="net45" />
</packages>

0 comments on commit c5e0b1e

Please sign in to comment.