Skip to content

Commit

Permalink
Merge pull request #54 from autofac/feature/net6
Browse files Browse the repository at this point in the history
Add .NET 6 target, enable NRT.
tillig authored May 26, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 92b54a7 + 44b8e1b commit 7104182
Showing 24 changed files with 476 additions and 453 deletions.
398 changes: 199 additions & 199 deletions .editorconfig

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"cSpell.words": [
"autofac",
"autowired",
"cref",
"interceptable",
"proxied",
"proxyable",
"proxying",
"xunit"
],
"coverage-gutters.coverageBaseDir": "artifacts/coverage",
"coverage-gutters.coverageFileNames": [
"coverage.info"
],
"dotnet-test-explorer.testProjectPath": "test/**/*Test.csproj",
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.resx": "$(capture).*.resx, $(capture).designer.cs, $(capture).designer.vb"
},
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableRoslynAnalyzers": true
}
Original file line number Diff line number Diff line change
@@ -20,13 +20,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
</ItemGroup>

<ItemGroup>
2 changes: 2 additions & 0 deletions build/Analyzers.ruleset
Original file line number Diff line number Diff line change
@@ -28,6 +28,8 @@
<Rule Id="SA1203" Action="None" />
<!-- Enforce order of static vs. non-static members -->
<Rule Id="SA1204" Action="None" />
<!-- Modifiers are not ordered - .editorconfig handles this -->
<Rule Id="SA1206" Action="None" />
<!-- Enforce order of readonly vs. non-readonly members -->
<Rule Id="SA1214" Action="None" />
<!-- Fields can't start with underscore -->
6 changes: 6 additions & 0 deletions build/Test.ruleset
Original file line number Diff line number Diff line change
@@ -4,6 +4,10 @@
<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" />
<!-- 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. -->
<Rule Id="CA1034" Action="None" />
<!-- Identifiers should not contain underscores - underscores are helpful in test naming. -->
<Rule Id="CA1707" 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. -->
@@ -32,6 +36,8 @@
<Rule Id="SA1203" Action="None" />
<!-- Enforce order of static vs. non-static members -->
<Rule Id="SA1204" Action="None" />
<!-- Modifiers are not ordered - .editorconfig handles this -->
<Rule Id="SA1206" Action="None" />
<!-- Enforce order of readonly vs. non-readonly members -->
<Rule Id="SA1214" Action="None" />
<!-- Fields can't start with underscore -->
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.200",
"version": "6.0.408",
"rollForward": "latestFeature"
}
}
35 changes: 26 additions & 9 deletions src/Autofac.Extras.DynamicProxy/Autofac.Extras.DynamicProxy.csproj
Original file line number Diff line number Diff line change
@@ -17,9 +17,11 @@
<!-- Frameworks and language features -->
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CodeAnalysisRuleSet>../../build/Analyzers.ruleset</CodeAnalysisRuleSet>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Packaging -->
@@ -37,12 +39,19 @@
<EmbedAllSources>true</EmbedAllSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<!-- OmniSharp/VS Code resource generation -->
<CoreCompileDependsOn>PrepareResources;$(CompileDependsOn)</CoreCompileDependsOn>
</PropertyGroup>

<ItemGroup>
<Using Include="System.Diagnostics.CodeAnalysis" />
</ItemGroup>

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

<ItemGroup>
<None Include="..\..\build\icon.png" Pack="true" PackagePath="\" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
@@ -53,20 +62,28 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.2.0" />
<PackageReference Include="Castle.Core" Version="5.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Autofac" Version="6.5.0" />
<PackageReference Include="Castle.Core" Version="5.1.1" />
<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.406">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemDefinitionGroup>
<EmbeddedResource>
<Generator>MSBuild:Compile</Generator>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedFileName>$(IntermediateOutputPath)%(Filename).Designer.cs</StronglyTypedFileName>
<StronglyTypedClassName>%(Filename)</StronglyTypedClassName>
</EmbeddedResource>
</ItemDefinitionGroup>

<ItemGroup>
<EmbeddedResource Update="RegistrationExtensionsResources.resx">
<StronglyTypedNamespace>Autofac.Extras.DynamicProxy</StronglyTypedNamespace>
</EmbeddedResource>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Autofac.Extras.DynamicProxy/InterceptAttribute.cs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ public class InterceptAttribute : Attribute
/// Initializes a new instance of the <see cref="InterceptAttribute"/> class.
/// </summary>
/// <param name="interceptorService">The interceptor service.</param>
/// <exception cref="System.ArgumentNullException">
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="interceptorService" /> is <see langword="null" />.
/// </exception>
public InterceptAttribute(Service interceptorService)
1 change: 0 additions & 1 deletion src/Autofac.Extras.DynamicProxy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Autofac Project. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Runtime.InteropServices;

[assembly: CLSCompliant(false)]
45 changes: 18 additions & 27 deletions src/Autofac.Extras.DynamicProxy/RegistrationExtensions.cs
Original file line number Diff line number Diff line change
@@ -153,20 +153,21 @@ public static IRegistrationBuilder<TLimit, TConcreteReflectionActivatorData, TRe
/// <param name="options">Proxy generation options to apply.</param>
/// <returns>Registration builder allowing the registration to be configured.</returns>
public static IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> EnableInterfaceInterceptors<TLimit, TActivatorData, TSingleRegistrationStyle>(
this IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> registration, ProxyGenerationOptions options = null)
this IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationStyle> registration, ProxyGenerationOptions? options = null)
{
if (registration == null)
{
throw new ArgumentNullException(nameof(registration));
}

registration.ConfigurePipeline(p => p.Use(PipelinePhase.Activation, MiddlewareInsertionMode.StartOfPhase, (ctxt, next) =>
registration.ConfigurePipeline(p => p.Use(PipelinePhase.Activation, MiddlewareInsertionMode.StartOfPhase, (ctx, next) =>
{
next(ctxt);
next(ctx);

EnsureInterfaceInterceptionApplies(ctxt.Registration);
EnsureInterfaceInterceptionApplies(ctx.Registration);

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

var interceptors = GetInterceptorServices(ctxt.Registration, ctxt.Instance.GetType())
.Select(s => ctxt.ResolveService(s))
var interceptors = GetInterceptorServices(ctx.Registration, ctx.Instance.GetType())
.Select(s => ctx.ResolveService(s))
.Cast<IInterceptor>()
.ToArray();

ctxt.Instance = options == null
? ProxyGenerator.CreateInterfaceProxyWithTarget(theInterface, interfaces, ctxt.Instance, interceptors)
: ProxyGenerator.CreateInterfaceProxyWithTarget(theInterface, interfaces, ctxt.Instance, options, interceptors);
ctx.Instance = options == null
? ProxyGenerator.CreateInterfaceProxyWithTarget(theInterface, interfaces, ctx.Instance, interceptors)
: ProxyGenerator.CreateInterfaceProxyWithTarget(theInterface, interfaces, ctx.Instance, options, interceptors);
}));

return registration;
@@ -202,7 +203,7 @@ public static IRegistrationBuilder<TLimit, TActivatorData, TSingleRegistrationSt
/// <param name="builder">Registration to apply interception to.</param>
/// <param name="interceptorServices">The interceptor services.</param>
/// <returns>Registration builder allowing the registration to be configured.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="builder"/> or <paramref name="interceptorServices"/>.</exception>
/// <exception cref="ArgumentNullException"><paramref name="builder"/> or <paramref name="interceptorServices"/>.</exception>
public static IRegistrationBuilder<TLimit, TActivatorData, TStyle> InterceptedBy<TLimit, TActivatorData, TStyle>(
this IRegistrationBuilder<TLimit, TActivatorData, TStyle> builder,
params Service[] interceptorServices)
@@ -286,10 +287,10 @@ private static void AddInterceptorServicesToMetadata<TLimit, TActivatorData, TSt
IEnumerable<Service> interceptorServices,
string metadataKey)
{
if (builder.RegistrationData.Metadata.TryGetValue(metadataKey, out object existing))
if (builder.RegistrationData.Metadata.TryGetValue(metadataKey, out object? existing) && existing is IEnumerable<Service> existingServices)
{
builder.RegistrationData.Metadata[metadataKey] =
((IEnumerable<Service>)existing).Concat(interceptorServices).Distinct();
existingServices.Concat(interceptorServices).Distinct();
}
else
{
@@ -299,25 +300,15 @@ private static void AddInterceptorServicesToMetadata<TLimit, TActivatorData, TSt

private static IEnumerable<Service> GetInterceptorServices(IComponentRegistration registration, Type implType)
{
if (registration == null)
{
throw new ArgumentNullException(nameof(registration));
}

if (implType == null)
{
throw new ArgumentNullException(nameof(implType));
}

var result = EmptyServices;

if (registration.Metadata.TryGetValue(InterceptorsPropertyName, out object services))
if (registration.Metadata.TryGetValue(InterceptorsPropertyName, out object? services) && services is IEnumerable<Service> existingPropertyServices)
{
result = result.Concat((IEnumerable<Service>)services);
result = result.Concat(existingPropertyServices);
}

return registration.Metadata.TryGetValue(AttributeInterceptorsPropertyName, out services)
? result.Concat((IEnumerable<Service>)services)
return (registration.Metadata.TryGetValue(AttributeInterceptorsPropertyName, out services) && services is IEnumerable<Service> existingAttributeServices)
? result.Concat(existingAttributeServices)
: result.Concat(GetInterceptorServicesFromAttributes(implType));
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -10,11 +10,13 @@
<PackageId>Autofac.Extras.DynamicProxy.Test.SatelliteAssembly</PackageId>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<CodeAnalysisRuleSet>../../build/Test.ruleset</CodeAnalysisRuleSet>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.406">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Original file line number Diff line number Diff line change
@@ -5,12 +5,12 @@ namespace Autofac.Extras.DynamicProxy.Test.SatelliteAssembly;

public class InterceptablePublicSatellite : IPublicInterfaceSatellite
{
public string PublicMethod()
public virtual string PublicMethod()
{
throw new NotImplementedException();
}

public string InternalMethod()
public virtual string InternalMethod()
{
throw new NotImplementedException();
}
Loading

0 comments on commit 7104182

Please sign in to comment.