Skip to content

Commit 7104182

Browse files
authored
Merge pull request #54 from autofac/feature/net6
Add .NET 6 target, enable NRT.
2 parents 92b54a7 + 44b8e1b commit 7104182

24 files changed

Lines changed: 476 additions & 453 deletions

.editorconfig

Lines changed: 199 additions & 199 deletions
Large diffs are not rendered by default.

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
{
22
"cSpell.words": [
33
"autofac",
4+
"autowired",
45
"cref",
6+
"interceptable",
7+
"proxied",
8+
"proxyable",
9+
"proxying",
510
"xunit"
611
],
712
"coverage-gutters.coverageBaseDir": "artifacts/coverage",
813
"coverage-gutters.coverageFileNames": [
914
"coverage.info"
1015
],
1116
"dotnet-test-explorer.testProjectPath": "test/**/*Test.csproj",
17+
"explorer.fileNesting.enabled": true,
18+
"explorer.fileNesting.patterns": {
19+
"*.resx": "$(capture).*.resx, $(capture).designer.cs, $(capture).designer.vb"
20+
},
1221
"omnisharp.enableEditorConfigSupport": true,
1322
"omnisharp.enableRoslynAnalyzers": true
1423
}

bench/Autofac.Extras.DynamicProxy.Benchmarks/Autofac.Extras.DynamicProxy.Benchmarks.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
24-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
23+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
24+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
2525
<PrivateAssets>all</PrivateAssets>
2626
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2727
</PackageReference>
28-
<PackageReference Include="xunit" Version="2.4.1" />
29-
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
28+
<PackageReference Include="xunit" Version="2.4.2" />
29+
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
3030
</ItemGroup>
3131

3232
<ItemGroup>

build/Analyzers.ruleset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<Rule Id="SA1203" Action="None" />
2929
<!-- Enforce order of static vs. non-static members -->
3030
<Rule Id="SA1204" Action="None" />
31+
<!-- Modifiers are not ordered - .editorconfig handles this -->
32+
<Rule Id="SA1206" Action="None" />
3133
<!-- Enforce order of readonly vs. non-readonly members -->
3234
<Rule Id="SA1214" Action="None" />
3335
<!-- Fields can't start with underscore -->

build/Test.ruleset

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
55
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
66
<Rule Id="CA1032" Action="None" />
7+
<!-- Do not nest types - we do that special for the DynamicProxy testing because there are lots of overlapping scenarios to test and interfaces/classes do need to be public. -->
8+
<Rule Id="CA1034" Action="None" />
9+
<!-- Identifiers should not contain underscores - underscores are helpful in test naming. -->
10+
<Rule Id="CA1707" Action="None" />
711
<!-- 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. -->
812
<Rule Id="CA1716" Action="None" />
913
<!-- Change Dispose() to call GC.SuppressFinalize - in tests we don't really care and it can impact readability. -->
@@ -32,6 +36,8 @@
3236
<Rule Id="SA1203" Action="None" />
3337
<!-- Enforce order of static vs. non-static members -->
3438
<Rule Id="SA1204" Action="None" />
39+
<!-- Modifiers are not ordered - .editorconfig handles this -->
40+
<Rule Id="SA1206" Action="None" />
3541
<!-- Enforce order of readonly vs. non-readonly members -->
3642
<Rule Id="SA1214" Action="None" />
3743
<!-- Fields can't start with underscore -->

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "6.0.200",
3+
"version": "6.0.408",
44
"rollForward": "latestFeature"
55
}
66
}

src/Autofac.Extras.DynamicProxy/Autofac.Extras.DynamicProxy.csproj

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
<!-- Frameworks and language features -->
1818
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
1919
<LangVersion>latest</LangVersion>
20+
<Nullable>enable</Nullable>
2021
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2122
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2223
<CodeAnalysisRuleSet>../../build/Analyzers.ruleset</CodeAnalysisRuleSet>
24+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
2325
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
2426
<ImplicitUsings>enable</ImplicitUsings>
2527
<!-- Packaging -->
@@ -37,12 +39,19 @@
3739
<EmbedAllSources>true</EmbedAllSources>
3840
<IncludeSymbols>true</IncludeSymbols>
3941
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
42+
<!-- OmniSharp/VS Code resource generation -->
43+
<CoreCompileDependsOn>PrepareResources;$(CompileDependsOn)</CoreCompileDependsOn>
4044
</PropertyGroup>
4145

4246
<ItemGroup>
4347
<Using Include="System.Diagnostics.CodeAnalysis" />
4448
</ItemGroup>
4549

50+
<!-- Disable nullability warnings in netstandard2.0 -->
51+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
52+
<NoWarn>$(NoWarn);8600;8601;8602;8603;8604</NoWarn>
53+
</PropertyGroup>
54+
4655
<ItemGroup>
4756
<None Include="..\..\build\icon.png" Pack="true" PackagePath="\" />
4857
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
@@ -53,20 +62,28 @@
5362
</ItemGroup>
5463

5564
<ItemGroup>
56-
<PackageReference Include="Autofac" Version="6.2.0" />
57-
<PackageReference Include="Castle.Core" Version="5.1.1" />
58-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
59-
<PrivateAssets>all</PrivateAssets>
60-
</PackageReference>
61-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
62-
<PrivateAssets>all</PrivateAssets>
63-
</PackageReference>
65+
<PackageReference Include="Autofac" Version="6.5.0" />
66+
<PackageReference Include="Castle.Core" Version="5.1.1" />
6467
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" Condition="Exists('$(MSBuildThisFileDirectory)../../.git')">
6568
<PrivateAssets>all</PrivateAssets>
6669
</PackageReference>
67-
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.406">
70+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
6871
<PrivateAssets>all</PrivateAssets>
6972
</PackageReference>
7073
</ItemGroup>
7174

75+
<ItemDefinitionGroup>
76+
<EmbeddedResource>
77+
<Generator>MSBuild:Compile</Generator>
78+
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
79+
<StronglyTypedFileName>$(IntermediateOutputPath)%(Filename).Designer.cs</StronglyTypedFileName>
80+
<StronglyTypedClassName>%(Filename)</StronglyTypedClassName>
81+
</EmbeddedResource>
82+
</ItemDefinitionGroup>
83+
84+
<ItemGroup>
85+
<EmbeddedResource Update="RegistrationExtensionsResources.resx">
86+
<StronglyTypedNamespace>Autofac.Extras.DynamicProxy</StronglyTypedNamespace>
87+
</EmbeddedResource>
88+
</ItemGroup>
7289
</Project>

src/Autofac.Extras.DynamicProxy/InterceptAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class InterceptAttribute : Attribute
2424
/// Initializes a new instance of the <see cref="InterceptAttribute"/> class.
2525
/// </summary>
2626
/// <param name="interceptorService">The interceptor service.</param>
27-
/// <exception cref="System.ArgumentNullException">
27+
/// <exception cref="ArgumentNullException">
2828
/// Thrown if <paramref name="interceptorService" /> is <see langword="null" />.
2929
/// </exception>
3030
public InterceptAttribute(Service interceptorService)

src/Autofac.Extras.DynamicProxy/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Autofac Project. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using System;
54
using System.Runtime.InteropServices;
65

76
[assembly: CLSCompliant(false)]

src/Autofac.Extras.DynamicProxy/RegistrationExtensions.cs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,21 @@ public static IRegistrationBuilder<TLimit, TConcreteReflectionActivatorData, TRe
153153
/// <param name="options">Proxy generation options to apply.</param>
154154
/// <returns>Registration builder allowing the registration to be configured.</returns>
155155
public static IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> EnableInterfaceInterceptors<TLimit, TActivatorData, TSingleRegistrationStyle>(
156-
this IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> registration, ProxyGenerationOptions options = null)
156+
this IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> registration, ProxyGenerationOptions? options = null)
157157
{
158158
if (registration == null)
159159
{
160160
throw new ArgumentNullException(nameof(registration));
161161
}
162162

163-
registration.ConfigurePipeline(p => p.Use(PipelinePhase.Activation, MiddlewareInsertionMode.StartOfPhase, (ctxt, next) =>
163+
registration.ConfigurePipeline(p => p.Use(PipelinePhase.Activation, MiddlewareInsertionMode.StartOfPhase, (ctx, next) =>
164164
{
165-
next(ctxt);
165+
next(ctx);
166166

167-
EnsureInterfaceInterceptionApplies(ctxt.Registration);
167+
EnsureInterfaceInterceptionApplies(ctx.Registration);
168168

169-
var proxiedInterfaces = ctxt.Instance
169+
// The instance won't ever _practically_ be null by the time it gets here.
170+
var proxiedInterfaces = ctx.Instance!
170171
.GetType()
171172
.GetInterfaces()
172173
.Where(ProxyUtil.IsAccessible)
@@ -180,14 +181,14 @@ public static IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationSt
180181
var theInterface = proxiedInterfaces.First();
181182
var interfaces = proxiedInterfaces.Skip(1).ToArray();
182183

183-
var interceptors = GetInterceptorServices(ctxt.Registration, ctxt.Instance.GetType())
184-
.Select(s => ctxt.ResolveService(s))
184+
var interceptors = GetInterceptorServices(ctx.Registration, ctx.Instance.GetType())
185+
.Select(s => ctx.ResolveService(s))
185186
.Cast<IInterceptor>()
186187
.ToArray();
187188

188-
ctxt.Instance = options == null
189-
? ProxyGenerator.CreateInterfaceProxyWithTarget(theInterface, interfaces, ctxt.Instance, interceptors)
190-
: ProxyGenerator.CreateInterfaceProxyWithTarget(theInterface, interfaces, ctxt.Instance, options, interceptors);
189+
ctx.Instance = options == null
190+
? ProxyGenerator.CreateInterfaceProxyWithTarget(theInterface, interfaces, ctx.Instance, interceptors)
191+
: ProxyGenerator.CreateInterfaceProxyWithTarget(theInterface, interfaces, ctx.Instance, options, interceptors);
191192
}));
192193

193194
return registration;
@@ -202,7 +203,7 @@ public static IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationSt
202203
/// <param name="builder">Registration to apply interception to.</param>
203204
/// <param name="interceptorServices">The interceptor services.</param>
204205
/// <returns>Registration builder allowing the registration to be configured.</returns>
205-
/// <exception cref="System.ArgumentNullException"><paramref name="builder"/> or <paramref name="interceptorServices"/>.</exception>
206+
/// <exception cref="ArgumentNullException"><paramref name="builder"/> or <paramref name="interceptorServices"/>.</exception>
206207
public static IRegistrationBuilder<TLimit, TActivatorData, TStyle> InterceptedBy<TLimit, TActivatorData, TStyle>(
207208
this IRegistrationBuilder<TLimit, TActivatorData, TStyle> builder,
208209
params Service[] interceptorServices)
@@ -286,10 +287,10 @@ private static void AddInterceptorServicesToMetadata<TLimit, TActivatorData, TSt
286287
IEnumerable<Service> interceptorServices,
287288
string metadataKey)
288289
{
289-
if (builder.RegistrationData.Metadata.TryGetValue(metadataKey, out object existing))
290+
if (builder.RegistrationData.Metadata.TryGetValue(metadataKey, out object? existing) && existing is IEnumerable<Service> existingServices)
290291
{
291292
builder.RegistrationData.Metadata[metadataKey] =
292-
((IEnumerable<Service>)existing).Concat(interceptorServices).Distinct();
293+
existingServices.Concat(interceptorServices).Distinct();
293294
}
294295
else
295296
{
@@ -299,25 +300,15 @@ private static void AddInterceptorServicesToMetadata<TLimit, TActivatorData, TSt
299300

300301
private static IEnumerable<Service> GetInterceptorServices(IComponentRegistration registration, Type implType)
301302
{
302-
if (registration == null)
303-
{
304-
throw new ArgumentNullException(nameof(registration));
305-
}
306-
307-
if (implType == null)
308-
{
309-
throw new ArgumentNullException(nameof(implType));
310-
}
311-
312303
var result = EmptyServices;
313304

314-
if (registration.Metadata.TryGetValue(InterceptorsPropertyName, out object services))
305+
if (registration.Metadata.TryGetValue(InterceptorsPropertyName, out object? services) && services is IEnumerable<Service> existingPropertyServices)
315306
{
316-
result = result.Concat((IEnumerable<Service>)services);
307+
result = result.Concat(existingPropertyServices);
317308
}
318309

319-
return registration.Metadata.TryGetValue(AttributeInterceptorsPropertyName, out services)
320-
? result.Concat((IEnumerable<Service>)services)
310+
return (registration.Metadata.TryGetValue(AttributeInterceptorsPropertyName, out services) && services is IEnumerable<Service> existingAttributeServices)
311+
? result.Concat(existingAttributeServices)
321312
: result.Concat(GetInterceptorServicesFromAttributes(implType));
322313
}
323314

0 commit comments

Comments
 (0)