-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Velir/issue-8
Fixed PerRequest dependency resolution in pipeline processor context
- Loading branch information
Showing
17 changed files
with
259 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Jabberwocky.Glass.Autofac.Mvc/Pipelines/Factories/Providers/MvcLifetimeScopeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Autofac; | ||
using Autofac.Integration.Mvc; | ||
using ILifetimeScopeProvider = Jabberwocky.Glass.Autofac.Pipelines.Factories.Providers.ILifetimeScopeProvider; | ||
|
||
namespace Jabberwocky.Glass.Autofac.Mvc.Pipelines.Factories.Providers | ||
{ | ||
public class MvcLifetimeScopeProvider : ILifetimeScopeProvider | ||
{ | ||
public ILifetimeScope GetLifetimeScope() | ||
{ | ||
return AutofacDependencyResolver.Current?.RequestLifetimeScope; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
Jabberwocky.Glass.Autofac.WebApi/Jabberwocky.Glass.Autofac.WebApi.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?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>{86B4E810-DCA7-4510-BA2B-EC1DDA9CB7FE}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Jabberwocky.Glass.Autofac.WebApi</RootNamespace> | ||
<AssemblyName>Jabberwocky.Glass.Autofac.WebApi</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="Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Autofac.3.5.2\lib\net40\Autofac.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Autofac.Integration.WebApi, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Autofac.WebApi2.3.3.3\lib\net45\Autofac.Integration.WebApi.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<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="Pipelines\Factories\Providers\WebApiLifetimeScopeProvider.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Jabberwocky.Glass.Autofac\Jabberwocky.Glass.Autofac.csproj"> | ||
<Project>{ea620f62-8d08-4031-bac4-1c60d5c5cbc9}</Project> | ||
<Name>Jabberwocky.Glass.Autofac</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</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> |
19 changes: 19 additions & 0 deletions
19
...erwocky.Glass.Autofac.WebApi/Pipelines/Factories/Providers/WebApiLifetimeScopeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Web.Http; | ||
using System.Web.Http.Dependencies; | ||
using Autofac; | ||
using Autofac.Integration.WebApi; | ||
using Jabberwocky.Glass.Autofac.Pipelines.Factories.Providers; | ||
|
||
namespace Jabberwocky.Glass.Autofac.WebApi.Pipelines.Factories.Providers | ||
{ | ||
public class WebApiLifetimeScopeProvider : ILifetimeScopeProvider | ||
{ | ||
public ILifetimeScope GetLifetimeScope() | ||
{ | ||
// If using the Autofac.WebApi integration package, this dependency should be of type 'AutofacWebApiDependencyResolver' | ||
var resolver = GlobalConfiguration.Configuration.DependencyResolver as IDependencyScope; | ||
|
||
return resolver?.GetRequestLifetimeScope(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Jabberwocky.Glass.Autofac.WebApi/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("Jabberwocky.Glass.Autofac.WebApi")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Microsoft")] | ||
[assembly: AssemblyProduct("Jabberwocky.Glass.Autofac.WebApi")] | ||
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")] | ||
[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("86b4e810-dca7-4510-ba2b-ec1dda9cb7fe")] | ||
|
||
// 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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Autofac" version="3.5.2" targetFramework="net45" /> | ||
<package id="Autofac.WebApi2" version="3.3.3" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" /> | ||
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" /> | ||
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Jabberwocky.Glass.Autofac/Pipelines/Factories/DefaultLifetimeScopeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Autofac; | ||
using Jabberwocky.Glass.Autofac.Pipelines.Factories.Providers; | ||
|
||
namespace Jabberwocky.Glass.Autofac.Pipelines.Factories | ||
{ | ||
internal class DefaultLifetimeScopeFactory : ILifetimeScopeFactory | ||
{ | ||
private readonly IEnumerable<ILifetimeScopeProvider> _scopeProviders; | ||
|
||
internal DefaultLifetimeScopeFactory(IEnumerable<ILifetimeScopeProvider> scopeProviders) | ||
{ | ||
if (scopeProviders == null) throw new ArgumentNullException(nameof(scopeProviders)); | ||
_scopeProviders = scopeProviders; | ||
} | ||
|
||
public ILifetimeScope GetCurrentLifetimeScope() | ||
{ | ||
return _scopeProviders | ||
.Select(provider => provider.GetLifetimeScope()) | ||
.FirstOrDefault(scope => scope != null); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Jabberwocky.Glass.Autofac/Pipelines/Factories/ILifetimeScopeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Autofac; | ||
|
||
namespace Jabberwocky.Glass.Autofac.Pipelines.Factories | ||
{ | ||
public interface ILifetimeScopeFactory | ||
{ | ||
ILifetimeScope GetCurrentLifetimeScope(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Jabberwocky.Glass.Autofac/Pipelines/Factories/Providers/ILifetimeScopeProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Autofac; | ||
|
||
namespace Jabberwocky.Glass.Autofac.Pipelines.Factories.Providers | ||
{ | ||
internal interface ILifetimeScopeProvider | ||
{ | ||
ILifetimeScope GetLifetimeScope(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters