Skip to content

Commit

Permalink
Merge pull request #1306 from autofac/feature/net6
Browse files Browse the repository at this point in the history
.NET 6 Support
  • Loading branch information
tillig authored Feb 23, 2022
2 parents be2a437 + 7511216 commit bb051cf
Show file tree
Hide file tree
Showing 112 changed files with 294 additions and 307 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"cSpell.words": [
"cref",
"xunit"
],
"dotnet-test-explorer.testProjectPath": "test/**/*Test.csproj",
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableRoslynAnalyzers": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions bench/Autofac.Benchmarks/Autofac.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<OutputType>Exe</OutputType>
<GenerateProgramFile>false</GenerateProgramFile>
Expand All @@ -12,7 +12,7 @@
<SignAssembly>true</SignAssembly>
<PackageId>Autofac.Benchmarks</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<CodeAnalysisRuleSet>../../build/Analyzers.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>../../build/Test.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,13 +28,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions bench/Autofac.Benchmarks/ChildScopeResolveBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public void Setup()
_container = builder.Build();
}

// Disable "unused parameter" warnings for test types.
#pragma warning disable IDE0060

internal class A
{
public A(B1 b1, B2 b2) { }
Expand Down Expand Up @@ -64,8 +61,5 @@ public C2(D1 d1, D2 d2) { }
internal class D1 { }

internal class D2 { }

#pragma warning restore IDE0060

}
}
6 changes: 0 additions & 6 deletions bench/Autofac.Benchmarks/ConcurrencyBenchmak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public async Task MultipleResolvesOnMultipleTasks()
await Task.WhenAll(tasks);
}

// Disable "unused parameter" warnings for test types.
#pragma warning disable IDE0060

internal class A
{
public A(B1 b1, B2 b2) { }
Expand Down Expand Up @@ -91,8 +88,5 @@ public C2(D1 d1, D2 d2) { }
internal class D1 { }

internal class D2 { }

#pragma warning restore IDE0060

}
}
5 changes: 0 additions & 5 deletions bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public async Task MultipleResolvesOnMultipleTasks()
await Task.WhenAll(tasks);
}

// Disable "unused parameter" warnings for test types.
#pragma warning disable IDE0060

internal class MockGlobalSingleton
{
}
Expand All @@ -91,7 +88,5 @@ internal class MockUnitOfWork
{
public MockUnitOfWork(MockGlobalSingleton singleton) {}
}

#pragma warning restore IDE0060
}
}
5 changes: 0 additions & 5 deletions bench/Autofac.Benchmarks/DeepGraphResolveBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public void Resolve()
GC.KeepAlive(instance);
}

// Disable "unused parameter" warnings for test types.
#pragma warning disable IDE0060

internal class A
{
public A(B1 b1, B2 b2) { }
Expand Down Expand Up @@ -62,7 +59,5 @@ public C2(D1 d1, D2 d2) { }
internal class D1 { }

internal class D2 { }

#pragma warning restore IDE0060
}
}
5 changes: 0 additions & 5 deletions bench/Autofac.Benchmarks/MultiConstructorBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ public void Four()
_container.Resolve<FourConstructors>();
}

// Disable "unused parameter" warnings for test types.
#pragma warning disable IDE0060

private class OneConstructor
{
public OneConstructor(D1 d1)
Expand Down Expand Up @@ -141,7 +138,5 @@ private class D3
private class D4
{
}

#pragma warning restore IDE0060
}
}
2 changes: 1 addition & 1 deletion bench/Autofac.Benchmarks/RootContainerResolveBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;

using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

Expand Down
62 changes: 62 additions & 0 deletions build/Test.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="16.0">
<IncludeAll Action="Warning" />
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
<Rule Id="CA1032" Action="None" />
<!-- Change names to avoid reserved word overlaps (e.g., Delegate, GetType, etc.) - too many of these in the public API, we'd break if we fixed it. -->
<Rule Id="CA1716" Action="None" />
<!-- Change Dispose() to call GC.SuppressFinalize - in tests we don't really care and it can impact readability. -->
<Rule Id="CA1816" Action="None" />
<!-- Mark members static - test methods may not access member data but also can't be static. -->
<Rule Id="CA1822" Action="None" />
<!-- Implement serialization constructors - false positive when building .NET Core -->
<Rule Id="CA2229" Action="None" />
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core -->
<Rule Id="CA2237" Action="None" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<!-- Prefix local calls with this -->
<Rule Id="SA1101" Action="None" />
<!-- Use built-in type alias -->
<Rule Id="SA1121" Action="None" />
<!-- Use String.Empty instead of "" -->
<Rule Id="SA1122" Action="None" />
<!-- Using statements must be inside a namespace -->
<Rule Id="SA1200" Action="None" />
<!-- Enforce order of class members by member type -->
<Rule Id="SA1201" Action="None" />
<!-- Enforce order of class members by member visibility -->
<Rule Id="SA1202" Action="None" />
<!-- Enforce order of constantand static members -->
<Rule Id="SA1203" Action="None" />
<!-- Enforce order of static vs. non-static members -->
<Rule Id="SA1204" Action="None" />
<!-- Enforce order of readonly vs. non-readonly members -->
<Rule Id="SA1214" Action="None" />
<!-- Fields can't start with underscore -->
<Rule Id="SA1309" Action="None" />
<!-- Suppressions must have a justification -->
<Rule Id="SA1404" Action="None" />
<!-- Use trailing comma in initializers - lots of false positives for enums in StyleCop 1.1.0-beta004 -->
<Rule Id="SA1413" Action="None" />
<!-- Parameter documentation mus be in the right order -->
<Rule Id="SA1612" Action="None" />
<!-- Return value must be documented -->
<Rule Id="SA1615" Action="None" />
<!-- Generic type parameters must be documented -->
<Rule Id="SA1618" Action="None" />
<!-- Don't copy/paste documentation -->
<Rule Id="SA1625" Action="None" />
<!-- Exception documentation must not be empty -->
<Rule Id="SA1627" Action="None" />
<!-- Enable XML documentation output-->
<Rule Id="SA1652" Action="None" />
<!-- Private member is unused - tests for reflection require members that may not get used. -->
<Rule Id="IDE0051" Action="None" />
<!-- Private member assigned value never read - tests for reflection require values that may not get used. -->
<Rule Id="IDE0052" Action="None" />
<!-- Remove unused parameter - tests for reflection require parameters that may not get used. -->
<Rule Id="IDE0060" Action="None" />
</Rules>
</RuleSet>
5 changes: 3 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"sdk": {
"version": "5.0.400",
"version": "6.0.200",
"rollForward": "latestFeature"
},

"additionalSdks": [
"3.1.413"
"3.1.416",
"5.0.405"
]
}
20 changes: 10 additions & 10 deletions src/Autofac/Autofac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>Autofac is an IoC container for Microsoft .NET. It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity.</Description>
<!-- VersionPrefix patched by AppVeyor -->
<VersionPrefix>0.0.1</VersionPrefix>
<TargetFrameworks>netstandard2.1;netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.1;netstandard2.0;</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);CS1591;IDE0008</NoWarn>
Expand All @@ -24,11 +24,11 @@
<NeutralLanguage>en-US</NeutralLanguage>
<Copyright>Copyright © 2015 Autofac Contributors</Copyright>
<CodeAnalysisRuleSet>../../build/Analyzers.ruleset</CodeAnalysisRuleSet>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<ContinuousIntegrationBuild Condition="'$(CI)' != '' ">true</ContinuousIntegrationBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedAllSources>true</EmbedAllSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<Features>IOperation</Features>
<Authors>Autofac Contributors</Authors>
<Company>Autofac</Company>
<Product>Autofac</Product>
Expand All @@ -48,17 +48,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.1">
<PrivateAssets>All</PrivateAssets>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
<PrivateAssets>All</PrivateAssets>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" Condition="Exists('$(MSBuildThisFileDirectory)../../.git')">
<PrivateAssets>All</PrivateAssets>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" Condition="Exists('$(MSBuildThisFileDirectory)../../.git')">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.205">
<PrivateAssets>All</PrivateAssets>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.406">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.7.1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Autofac/Builder/BuildCallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Autofac.Builder
/// </summary>
internal static class BuildCallbackManager
{
private static readonly TypedService CallbackServiceType = new TypedService(typeof(BuildCallbackService));
private static readonly TypedService CallbackServiceType = new(typeof(BuildCallbackService));

private const string BuildCallbacksExecutedKey = nameof(BuildCallbacksExecutedKey);

Expand Down
2 changes: 1 addition & 1 deletion src/Autofac/Builder/BuildCallbackService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Autofac.Builder
/// </summary>
internal class BuildCallbackService
{
private List<Action<ILifetimeScope>> _callbacks = new List<Action<ILifetimeScope>>();
private List<Action<ILifetimeScope>> _callbacks = new();

/// <summary>
/// Add a callback to the set that will get executed.
Expand Down
2 changes: 1 addition & 1 deletion src/Autofac/Builder/RegistrationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static IComponentRegistration CreateRegistration(
{
foreach (var ts in services)
{
if (!(ts is IServiceWithType asServiceWithType))
if (ts is not IServiceWithType asServiceWithType)
{
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Autofac/Core/Activators/DelegatePropertySelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public DelegatePropertySelector(Func<PropertyInfo, object, bool> finder)
}

/// <inheritdoc/>
public bool InjectProperty(PropertyInfo property, object instance)
public bool InjectProperty(PropertyInfo propertyInfo, object instance)
{
return _finder(property, instance);
return _finder(propertyInfo, instance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ internal static class AutowiringPropertyInjector
/// </summary>
internal const string InstanceTypeNamedParameter = "Autofac.AutowiringPropertyInjector.InstanceType";

private static readonly ConcurrentDictionary<PropertyInfo, Action<object, object?>> PropertySetters =
new ConcurrentDictionary<PropertyInfo, Action<object, object?>>();
private static readonly ConcurrentDictionary<PropertyInfo, Action<object, object?>> PropertySetters = new();

private static readonly ConcurrentDictionary<Type, PropertyInfo[]> InjectableProperties =
new ConcurrentDictionary<Type, PropertyInfo[]>();
private static readonly ConcurrentDictionary<Type, PropertyInfo[]> InjectableProperties = new();

private static readonly MethodInfo CallPropertySetterOpenGenericMethod =
typeof(AutowiringPropertyInjector).GetDeclaredMethod(nameof(CallPropertySetter));
Expand Down
4 changes: 2 additions & 2 deletions src/Autofac/Core/Activators/Reflection/BoundConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public class BoundConstructor
/// <param name="valueRetrievers">The set of value-retrieval functions.</param>
[SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Validated in constructor.")]
public static BoundConstructor ForBindSuccess(ConstructorBinder binder, Func<object?[], object> factory, Func<object?>[] valueRetrievers)
=> new BoundConstructor(binder, factory, valueRetrievers);
=> new(binder, factory, valueRetrievers);

/// <summary>
/// Initializes a new instance of the <see cref="BoundConstructor"/> class, for an unsuccessful bind.
/// </summary>
/// <param name="binder">The binder that generated this binding.</param>
/// <param name="firstNonBindableParameter">The first parameter that prevented binding.</param>
public static BoundConstructor ForBindFailure(ConstructorBinder binder, ParameterInfo firstNonBindableParameter) =>
new BoundConstructor(binder, firstNonBindableParameter);
new(binder, firstNonBindableParameter);

/// <summary>
/// Initializes a new instance of the <see cref="BoundConstructor"/> class for a successful bind.
Expand Down
4 changes: 2 additions & 2 deletions src/Autofac/Core/Activators/Reflection/ConstructorBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ConstructorBinder
{
private static readonly Func<ConstructorInfo, Func<object?[], object>> FactoryBuilder = GetConstructorInvoker;

private static readonly ConcurrentDictionary<ConstructorInfo, Func<object?[], object>> FactoryCache = new ConcurrentDictionary<ConstructorInfo, Func<object?[], object>>();
private static readonly ConcurrentDictionary<ConstructorInfo, Func<object?[], object>> FactoryCache = new();

private readonly ParameterInfo[] _constructorArgs;
private readonly Func<object?[], object>? _factory;
Expand Down Expand Up @@ -84,7 +84,7 @@ public BoundConstructor Bind(IEnumerable<Parameter> availableParameters, ICompon
return BoundConstructor.ForBindSuccess(this, _factory!, Array.Empty<Func<object?>>());
}

if (_illegalParameter is object)
if (_illegalParameter is not null)
{
return BoundConstructor.ForBindFailure(this, _illegalParameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DefaultConstructorFinder : IConstructorFinder
{
private readonly Func<Type, ConstructorInfo[]> _finder;

private static readonly ConcurrentDictionary<Type, ConstructorInfo[]> DefaultPublicConstructorsCache = new ConcurrentDictionary<Type, ConstructorInfo[]>();
private static readonly ConcurrentDictionary<Type, ConstructorInfo[]> DefaultPublicConstructorsCache = new();

/// <summary>
/// Initializes a new instance of the <see cref="DefaultConstructorFinder" /> class.
Expand Down
4 changes: 2 additions & 2 deletions src/Autofac/Core/Disposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ internal class Disposer : Disposable, IDisposer
/// <summary>
/// Contents all implement IDisposable or IAsyncDisposable.
/// </summary>
private Stack<object> _items = new Stack<object>();
private Stack<object> _items = new();

// Need to use a semaphore instead of a simple object to lock on, because
// we need to synchronise an awaitable block.
private readonly SemaphoreSlim _synchRoot = new SemaphoreSlim(1, 1);
private readonly SemaphoreSlim _synchRoot = new(1, 1);

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
Expand Down
Loading

0 comments on commit bb051cf

Please sign in to comment.