Skip to content

Commit

Permalink
Merge pull request #83 from matt-sullivan/035e3faf11ecf4ba2088ecb3aad…
Browse files Browse the repository at this point in the history
…2bc6fb9c9ba88

Add AutofacAggregateRootCreationStrategy
  • Loading branch information
pjvds committed Mar 22, 2015
2 parents 514e736 + 035e3fa commit 2bd93b4
Show file tree
Hide file tree
Showing 21 changed files with 6,508 additions and 49 deletions.
83 changes: 41 additions & 42 deletions Extensions/NcqrsExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.Eventing.Storage.JOliver.RavenPersistence", "src\Ncqrs.Eventing.Storage.JOliver.RavenPersistence\Ncqrs.Eventing.Storage.JOliver.RavenPersistence.csproj", "{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.EventBus.Tests", "src\Ncqrs.EventBus.Tests\Ncqrs.EventBus.Tests.csproj", "{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.Eventing.Storage.JOliver.Tests", "src\Ncqrs.Eventing.Storage.JOliver.Tests\Ncqrs.Eventing.Storage.JOliver.Tests.csproj", "{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.Eventing.Storage.MongoDB", "src\Ncqrs.Eventing.Storage.MongoDB\Ncqrs.Eventing.Storage.MongoDB.csproj", "{E421E735-2833-4948-9BA0-94924BDC502E}"
Expand All @@ -65,6 +66,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.Eventing.Sourcing.Sna
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.Eventing.Sourcing.Snapshotting.DynamicSnapshot.Tests", "src\Ncqrs.Eventing.Sourcing.Snapshotting.DynamicSnapshot.Tests\Ncqrs.Eventing.Sourcing.Snapshotting.DynamicSnapshot.Tests.csproj", "{85073A89-CC13-44E2-B8C2-FB0B638B60F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.Config.Autofac", "src\Ncqrs.Config.Autofac\Ncqrs.Config.Autofac.csproj", "{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.Config.Autofac.Tests", "src\Ncqrs.Config.Autofac.Tests\Ncqrs.Config.Autofac.Tests.csproj", "{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ncqrs.RhinoServiceBus", "src\Ncqrs.RhinoServiceBus\Ncqrs.RhinoServiceBus.csproj", "{D3C73A73-3770-495C-A6B2-621DD67EB48A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -215,12 +222,14 @@ Global
{9CBAEAFE-9265-47BA-82C5-5E0774CBF2C5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9CBAEAFE-9265-47BA-82C5-5E0774CBF2C5}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9CBAEAFE-9265-47BA-82C5-5E0774CBF2C5}.Release|x86.ActiveCfg = Release|Any CPU
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Debug|Any CPU.ActiveCfg = Debug|x86
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Debug|Mixed Platforms.Build.0 = Debug|x86
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Debug|x86.ActiveCfg = Debug|x86
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Debug|x86.Build.0 = Debug|x86
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Release|Any CPU.ActiveCfg = Release|x86
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Release|Any CPU.Build.0 = Release|Any CPU
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Release|Mixed Platforms.ActiveCfg = Release|x86
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Release|Mixed Platforms.Build.0 = Release|x86
{DC0FB020-79D9-497E-8869-9508FCFA6537}.Release|x86.ActiveCfg = Release|x86
Expand Down Expand Up @@ -315,46 +324,6 @@ Global
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Release|x86.ActiveCfg = Release|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Debug|x86.ActiveCfg = Debug|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Release|Any CPU.Build.0 = Release|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EE6E54C8-D108-49E7-9E2A-6BAEF6D5339F}.Release|x86.ActiveCfg = Release|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Debug|x86.ActiveCfg = Debug|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Release|Any CPU.Build.0 = Release|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{DCA6E39A-8D6B-4531-ACA7-33D790D27878}.Release|x86.ActiveCfg = Release|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Debug|x86.ActiveCfg = Debug|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Release|Any CPU.Build.0 = Release|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{A2ADE0B3-D3C0-4D6B-8701-C0F5E509A69A}.Release|x86.ActiveCfg = Release|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Debug|x86.ActiveCfg = Debug|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Release|Any CPU.Build.0 = Release|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{7C4B1AD0-C354-47D1-A9AB-793AE2AD52A2}.Release|x86.ActiveCfg = Release|Any CPU
{E421E735-2833-4948-9BA0-94924BDC502E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E421E735-2833-4948-9BA0-94924BDC502E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E421E735-2833-4948-9BA0-94924BDC502E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -415,6 +384,36 @@ Global
{85073A89-CC13-44E2-B8C2-FB0B638B60F7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{85073A89-CC13-44E2-B8C2-FB0B638B60F7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{85073A89-CC13-44E2-B8C2-FB0B638B60F7}.Release|x86.ActiveCfg = Release|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Debug|x86.ActiveCfg = Debug|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Release|Any CPU.Build.0 = Release|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}.Release|x86.ActiveCfg = Release|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Debug|x86.ActiveCfg = Debug|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Release|Any CPU.Build.0 = Release|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}.Release|x86.ActiveCfg = Release|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Debug|x86.ActiveCfg = Debug|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Release|Any CPU.Build.0 = Release|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{D3C73A73-3770-495C-A6B2-621DD67EB48A}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<Private>False</Private>
</Reference>
<Reference Include="Ncqrs.CommandService.Contracts">
<HintPath>..\..\..\lib\Debug\Ncqrs.CommandService.Contracts\Ncqrs.CommandService.Contracts.dll</HintPath>
<HintPath>..\..\..\lib\$(Configuration)\Ncqrs.CommandService.Contracts\Ncqrs.CommandService.Contracts.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Autofac;
using FluentAssertions;
using NUnit.Framework;

namespace Ncqrs.Config.Autofac.Tests
{
[TestFixture]
public class AutofacConfigurationTests
{
[Test]
public void When_component_is_registered_it_should_be_retrievable()
{
var kernel = new ContainerBuilder();
kernel.RegisterType<Nexus6>().As<IReplicant>();

var container = kernel.Build();
var configuration = new AutofacConfiguration(container);

IReplicant component;
var success = configuration.TryGet(out component);

success.Should().BeTrue();
component.Should().NotBeNull();
component.Should().BeOfType<IReplicant>();
}

[Test]
public void When_component_is_not_registered_it_should_not_be_retrievable()
{
var kernel = new ContainerBuilder();
var container = kernel.Build();
var configuration = new AutofacConfiguration(container);

IReplicant component;
var success = configuration.TryGet(out component);

success.Should().BeFalse();
component.Should().BeNull();
}
}

public interface IReplicant { }

public class Nexus6 : IReplicant { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7AF9F0CC-E3BC-4D02-9CD8-17CF8F635F05}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Ncqrs.Config.Autofac.Tests</RootNamespace>
<AssemblyName>Ncqrs.Config.Autofac.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</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="Autofac">
<HintPath>..\..\..\lib\ThirdParty\Autofac\Autofac.dll</HintPath>
</Reference>
<Reference Include="FluentAssertions">
<HintPath>..\..\..\lib\ThirdParty\FluentAssertions\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="Ncqrs">
<HintPath>..\..\..\lib\Debug\Ncqrs\Ncqrs.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.5.8.10295, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\ThirdParty\Nunit\nunit.framework.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="AutofacConfigurationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Ncqrs.Config.Autofac\Ncqrs.Config.Autofac.csproj">
<Project>{0EBAECFC-9A56-4ADD-AD41-7B007CFF99F1}</Project>
<Name>Ncqrs.Config.Autofac</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>
Original file line number Diff line number Diff line change
@@ -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("Ncqrs.Config.Autofac.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Ncqrs.Config.Autofac.Tests")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[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("afd65908-b1ca-4cf6-870c-2c0ccc8520e9")]

// 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")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Ncqrs.Config.Autofac
{
using System;
using Ncqrs.Domain;
using Ncqrs.Domain.Storage;

using global::Autofac;

/// <summary>
/// Use Autofac to create AggregateRoots for the domain repository. (This allows the domain
/// repository to re-construct AggregateRoots to their current state, but also have
/// dependencies injected.
/// </summary>
public class AutofacAggregateRootCreationStrategy : AggregateRootCreationStrategy
{
private readonly ILifetimeScope _containerScope;

public AutofacAggregateRootCreationStrategy(ILifetimeScope containerScope)
{
_containerScope = containerScope;
}

protected override AggregateRoot CreateAggregateRootFromType(Type aggregateRootType)
{
return (AggregateRoot)_containerScope.Resolve(aggregateRootType);
}

}
}
38 changes: 38 additions & 0 deletions Extensions/src/Ncqrs.Config.Autofac/AutofacConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ncqrs;
using Autofac;

namespace Ncqrs.Config.Autofac
{
public class AutofacConfiguration : IEnvironmentConfiguration
{
readonly IContainer container;

/// <summary>
/// Initializes a new instance of the <see cref="AutofacConfiguration"/> class.
/// </summary>
/// <param name="container">The Autofac container which will provide components to Ncqrs.</param>
public AutofacConfiguration(IContainer container)
{
this.container = container;
}

/// <summary>
/// Tries to get the specified instance.
/// </summary>
/// <typeparam name="T">The type of the instance to get.</typeparam>
/// <param name="result">The result.</param>
/// <returns>A indication whether the instance could be get or not.</returns>
public bool TryGet<T>(out T result) where T : class
{
result = container.ResolveOptional<T>();

return result != null;
}
}
}


Loading

0 comments on commit 2bd93b4

Please sign in to comment.