Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:autofac/Autofac into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weelink committed Feb 3, 2020
2 parents 29cdc48 + cf3674a commit 190efc9
Show file tree
Hide file tree
Showing 131 changed files with 2,820 additions and 1,491 deletions.
19 changes: 19 additions & 0 deletions Autofac.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autofac.Test.Scenarios.Scan
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autofac.Specification.Test", "test\Autofac.Specification.Test\Autofac.Specification.Test.csproj", "{39610DBF-4CAF-45FD-8B9F-D8928D76066A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Autofac.Test.Compilation", "test\Autofac.Test.Compilation\Autofac.Test.Compilation.csproj", "{0307A6FE-171A-4642-95A0-90AB80879BB4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -131,6 +133,22 @@ Global
{39610DBF-4CAF-45FD-8B9F-D8928D76066A}.Release|x64.Build.0 = Release|Any CPU
{39610DBF-4CAF-45FD-8B9F-D8928D76066A}.Release|x86.ActiveCfg = Release|Any CPU
{39610DBF-4CAF-45FD-8B9F-D8928D76066A}.Release|x86.Build.0 = Release|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Debug|ARM.ActiveCfg = Debug|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Debug|ARM.Build.0 = Debug|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Debug|x64.ActiveCfg = Debug|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Debug|x64.Build.0 = Debug|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Debug|x86.ActiveCfg = Debug|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Debug|x86.Build.0 = Debug|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Release|Any CPU.Build.0 = Release|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Release|ARM.ActiveCfg = Release|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Release|ARM.Build.0 = Release|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Release|x64.ActiveCfg = Release|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Release|x64.Build.0 = Release|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Release|x86.ActiveCfg = Release|Any CPU
{0307A6FE-171A-4642-95A0-90AB80879BB4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -141,6 +159,7 @@ Global
{D7A37F73-BBA3-4DAE-9648-1A753A86F968} = {48F40A36-C829-4895-99B3-1634CC6594E0}
{49FB428A-28D6-4A60-AF29-B9D5F7552041} = {DEA4A8C6-DE56-4359-A87C-472FB34132E7}
{39610DBF-4CAF-45FD-8B9F-D8928D76066A} = {DEA4A8C6-DE56-4359-A87C-472FB34132E7}
{0307A6FE-171A-4642-95A0-90AB80879BB4} = {DEA4A8C6-DE56-4359-A87C-472FB34132E7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2D16574C-61CB-4568-8490-AC9B85A721C0}
Expand Down
2 changes: 2 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Is this for Autofac 5? [Read the release notes!](https://github.com/autofac/Autofac/releases/tag/v5.0.0) We are working on updating integration libraries but they're not all done. Please don't file issues about integration library incompatibility until you get the updated version which may not yet be published! If you really need it faster, a PR directly to the integration library will speed it up! (When the integration library is posted, file additional issues in that repo. THIS IS FOR CORE AUTOFAC ONLY.)

Try StackOverflow! If you have a _usage question_ ("How do I...?" "Others have this working but I can't get it...") please try [StackOverflow](https://stackoverflow.com) and tag your question `autofac`. We, along with a great community, monitor those questions.

**Have you [read the docs?](https://autofac.readthedocs.io/)**
Expand Down
4 changes: 2 additions & 2 deletions bench/Autofac.Benchmarks/Autofac.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions bench/Autofac.Benchmarks/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal static class Benchmarks
{
typeof(ChildScopeResolveBenchmark),
typeof(ConcurrencyBenchmark),
typeof(ConcurrencyNestedScopeBenchmark),
typeof(KeyedGenericBenchmark),
typeof(KeyedNestedBenchmark),
typeof(KeyedSimpleBenchmark),
Expand Down
8 changes: 4 additions & 4 deletions bench/Autofac.Benchmarks/ConcurrencyBenchmak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public ConcurrencyBenchmark()
_container = builder.Build();
}

[Params(10 /*, 100, 1_000 */)]
[Params(100 /*, 100, 1_000 */)]
public int ResolveTaskCount { get; set; }

[Params(10 /*, 1_000, 10_000 */)]
[Params(100 /*, 1_000, 10_000 */)]
public int ResolvesPerTask { get; set; }

[Benchmark]
public void MultipleResolvesOnMultipleTasks()
public async Task MultipleResolvesOnMultipleTasks()
{
var tasks = new List<Task>(ResolveTaskCount);

Expand All @@ -57,7 +57,7 @@ public void MultipleResolvesOnMultipleTasks()
tasks.Add(task);
}

Task.WhenAll(tasks);
await Task.WhenAll(tasks);
}

internal class A
Expand Down
92 changes: 92 additions & 0 deletions bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using BenchmarkDotNet.Attributes;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;

namespace Autofac.Benchmarks
{
/// <summary>
/// Test the performance of resolving a relatively simple object graph, but within 2 levels of nested lifetime scopes,
/// to simulate a 'per-request' scope model, combined with a unit-of-work inside request.
/// </summary>
public class ConcurrencyNestedScopeBenchmark
{
private readonly IContainer _container;

public ConcurrencyNestedScopeBenchmark()
{
var builder = new ContainerBuilder();
builder.RegisterType<MockGlobalSingleton>().SingleInstance();
builder.RegisterType<MockRequestScopeService1>().InstancePerMatchingLifetimeScope("request");
builder.RegisterType<MockRequestScopeService2>().InstancePerMatchingLifetimeScope("request");
builder.RegisterType<MockUnitOfWork>().InstancePerLifetimeScope();
_container = builder.Build();
}

[Params(100 /*, 100, 1_000 */)]
public int ConcurrentRequests { get; set; }

[Params(10)]
public int RepeatCount { get; set; }

[Benchmark]
public async Task MultipleResolvesOnMultipleTasks()
{
var tasks = new List<Task>(ConcurrentRequests);

for (var i = 0; i < ConcurrentRequests; i++)
{
var task = Task.Run(() =>
{
try
{
for (var j = 0; j < RepeatCount; j++)
{
// Start request
using(var requestScope = _container.BeginLifetimeScope("request"))
{
var service1 = requestScope.Resolve<MockRequestScopeService1>();
Assert.NotNull(service1);

using (var unitOfWorkScope = requestScope.BeginLifetimeScope())
{
var nestedRequestService2 = unitOfWorkScope.Resolve<MockRequestScopeService2>();
Assert.NotNull(nestedRequestService2);
var unitOfWork = unitOfWorkScope.Resolve<MockUnitOfWork>();
Assert.NotNull(unitOfWork);
}
}
}
}
catch (Exception ex)
{
Assert.True(false, ex.ToString());
}
});
tasks.Add(task);
}

await Task.WhenAll(tasks);
}

internal class MockGlobalSingleton
{
}

internal class MockRequestScopeService1
{
public MockRequestScopeService1() { }
}

internal class MockRequestScopeService2
{
public MockRequestScopeService2(MockRequestScopeService1 service1, MockGlobalSingleton singleton) { }
}

internal class MockUnitOfWork
{
public MockUnitOfWork(MockGlobalSingleton singleton) {}
}
}
}
3 changes: 3 additions & 0 deletions bench/Autofac.Benchmarks/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class Harness
[Fact]
public void Concurrency() => RunBenchmark<ConcurrencyBenchmark>();

[Fact]
public void ConcurrencyNestedScopes() => RunBenchmark<ConcurrencyNestedScopeBenchmark>();

[Fact]
public void Decorator_Keyed_Generic() => RunBenchmark<KeyedGenericBenchmark>();

Expand Down
Binary file added build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 25 additions & 6 deletions src/Autofac/Autofac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<VersionPrefix>5.0.0</VersionPrefix>
<TargetFrameworks>netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);CS1591;IDE0008</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -15,7 +16,7 @@
<PackageId>Autofac</PackageId>
<PackageTags>autofac;di;ioc;dependencyinjection</PackageTags>
<PackageReleaseNotes>Release notes are at https://github.com/autofac/Autofac/releases</PackageReleaseNotes>
<PackageIconUrl>https://cloud.githubusercontent.com/assets/1156571/13684110/16b8f152-e6bf-11e5-84ae-22c66c6d351a.png</PackageIconUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://autofac.org</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
Expand All @@ -35,30 +36,44 @@
<Product>Autofac</Product>
</PropertyGroup>

<!-- Disable nullability warnings in netstandard2.0 and net461 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461'">
<NoWarn>$(NoWarn);8600;8601;8602;8603;8604</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\build\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.4">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.8">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-62925-02" Condition="Exists('$(MSBuildThisFileDirectory)../../.git')">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" Condition="Exists('$(MSBuildThisFileDirectory)../../.git')">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.113">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461' ">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0-preview1.19504.10" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.ComponentModel.Composition" />
</ItemGroup>

<ItemGroup>
<Compile Update="Builder\BuildCallbackServiceResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>BuildCallbackServiceResources.resx</DependentUpon>
</Compile>
<Compile Update="Builder\RegistrationBuilderResources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -267,6 +282,10 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Builder\BuildCallbackServiceResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>BuildCallbackServiceResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Builder\RegistrationBuilderResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>RegistrationBuilderResources.Designer.cs</LastGenOutput>
Expand Down
62 changes: 62 additions & 0 deletions src/Autofac/Builder/BuildCallbackManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This software is part of the Autofac IoC container
// Copyright © 2019 Autofac Contributors
// https://autofac.org
//
// 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.Linq;
using Autofac.Core;

namespace Autofac.Builder
{
internal static class BuildCallbackManager
{
private static readonly TypedService CallbackServiceType = new TypedService(typeof(BuildCallbackService));

private const string BuildCallbacksExecutedKey = nameof(BuildCallbacksExecutedKey);

/// <summary>
/// Executes the newly-registered build callbacks for a given scope/container..
/// </summary>
/// <param name="scope">The new scope/container.</param>
internal static void RunBuildCallbacks(ILifetimeScope scope)
{
var buildCallbackServices = scope.ComponentRegistry.RegistrationsFor(CallbackServiceType);

foreach (var srv in buildCallbackServices)
{
// Use the metadata to track whether we've executed already, to avoid issuing a resolve request.
if (srv.Metadata.ContainsKey(BuildCallbacksExecutedKey))
{
continue;
}

var request = new ResolveRequest(CallbackServiceType, srv, Enumerable.Empty<Parameter>());
var component = (BuildCallbackService)scope.ResolveComponent(request);
srv.Metadata[BuildCallbacksExecutedKey] = true;

// Run the callbacks for the relevant scope.
component.Execute(scope);
}
}
}
}
Loading

0 comments on commit 190efc9

Please sign in to comment.