Skip to content

Commit 283c325

Browse files
authored
Merge pull request #20 from autofac/feature/build-metadata-update
Standardize build metadata and code formatting
2 parents afd4a8b + d0af6ee commit 283c325

28 files changed

Lines changed: 1053 additions & 883 deletions

.editorconfig

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

build/Source.ruleset

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,39 @@
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+
<!-- Avoid excessive inheritance (must be explicitly enabled). -->
8+
<Rule Id="CA1501" Action="Warning" />
9+
<!-- Avoid excessive complexity (must be explicitly enabled). -->
10+
<Rule Id="CA1502" Action="Warning" />
11+
<!-- Avoid unmaintainable code (must be explicitly enabled). -->
12+
<Rule Id="CA1505" Action="Warning" />
13+
<!-- Avoid excessive class coupling (must be explicitly enabled). -->
14+
<Rule Id="CA1506" Action="Warning" />
15+
<!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. -->
16+
<Rule Id="CA1510" Action="None" />
17+
<!-- Use ArgumentOutOfRangeException.ThrowIfNegative - this isn't available until we stop targeting anything below net8.0. -->
18+
<Rule Id="CA1512" Action="None" />
19+
<!-- Use ObjectDisposedException.ThrowIf - this isn't available until we stop targeting anything below net8.0. -->
20+
<Rule Id="CA1513" Action="None" />
721
<!-- 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. -->
822
<Rule Id="CA1716" Action="None" />
9-
<!-- Implement serialization constructors - false positive when building .NET Core -->
23+
<!-- Cache a CompositeFormat object for use in String.Format - this isn't available until we stop targeting netstandard, and we only String.Format when throwing exceptions so the work/complexity isn't justified to increase perf just for those situations. -->
24+
<Rule Id="CA1863" Action="None" />
25+
<!-- Implement serialization constructors - false positive when building .NET Core. -->
1026
<Rule Id="CA2229" Action="None" />
11-
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core -->
27+
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core. -->
1228
<Rule Id="CA2237" Action="None" />
29+
<!-- Prefer generic overloads to using Type parameters - many aren't available in earlier frameworks; and we do a lot of reflection work in Autofac. -->
30+
<Rule Id="CA2263" Action="None" />
1331
</Rules>
1432
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
15-
<!-- Prefix local calls with this -->
33+
<!-- Prefix local calls with this. -->
1634
<Rule Id="SA1101" Action="None" />
17-
<!-- Use built-in type alias -->
35+
<!-- Use built-in type alias. -->
1836
<Rule Id="SA1121" Action="None" />
19-
<!-- Use String.Empty instead of "" -->
37+
<!-- Use String.Empty instead of "". -->
2038
<Rule Id="SA1122" Action="None" />
21-
<!-- Using statements must be inside a namespace -->
22-
<Rule Id="SA1200" Action="None" />
23-
<!-- Fields can't start with underscore -->
39+
<!-- Fields can't start with underscore. -->
2440
<Rule Id="SA1309" Action="None" />
2541
</Rules>
2642
</RuleSet>

build/Test.ruleset

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,92 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac test assemblies." ToolsVersion="16.0">
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="16.0">
33
<IncludeAll Action="Warning" />
44
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
5+
<!-- Avoid excessive parameters on generic types (must be explicitly enabled). -->
56
<Rule Id="CA1005" Action="Warning" />
7+
<!-- Don't catch general exceptions - test scenarios sometimes require general exception handling. -->
68
<Rule Id="CA1031" Action="None" />
9+
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
710
<Rule Id="CA1032" Action="None" />
11+
<!-- Avoid empty interfaces - in unit tests for service resolution, this happens a lot. -->
812
<Rule Id="CA1040" Action="None" />
13+
<!-- Do not pass literals as localized parameters - tests don't need to localize. -->
914
<Rule Id="CA1303" Action="None" />
15+
<!-- Avoid excessive inheritance (must be explicitly enabled). -->
1016
<Rule Id="CA1501" Action="Warning" />
17+
<!-- Avoid excessive complexity (must be explicitly enabled). -->
1118
<Rule Id="CA1502" Action="Warning" />
19+
<!-- Avoid unmaintainable code (must be explicitly enabled). -->
1220
<Rule Id="CA1505" Action="Warning" />
21+
<!-- Avoid excessive class coupling (must be explicitly enabled). -->
1322
<Rule Id="CA1506" Action="Warning" />
23+
<!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. -->
1424
<Rule Id="CA1510" Action="None" />
25+
<!-- Make API types internal - causes problems with tests and test assemblies. -->
1526
<Rule Id="CA1515" Action="None" />
27+
<!-- Remove the underscores from member name - unit test scenarios may use underscores. -->
1628
<Rule Id="CA1707" Action="None" />
29+
<!-- 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. -->
1730
<Rule Id="CA1716" Action="None" />
31+
<!-- Internal class that appears to never be instantiated - lots of false positives here because they're test stubs created by Autofac registrations. -->
1832
<Rule Id="CA1812" Action="None" />
33+
<!-- Change Dispose() to call GC.SuppressFinalize - in tests we don't really care and it can impact readability. -->
1934
<Rule Id="CA1816" Action="None" />
35+
<!-- Mark members static - test methods may not access member data but also can't be static. -->
2036
<Rule Id="CA1822" Action="None" />
37+
<!-- Seal internal types for performance - in tests we don't really care and it gets painful to enforce. -->
2138
<Rule Id="CA1852" Action="None" />
39+
<!-- Prefer static readonly fields over constant array arguments - constant array arguments happen a lot in unit tests for assertions and test setup. -->
2240
<Rule Id="CA1861" Action="None" />
41+
<!-- Cache a CompositeFormat object for use in String.Format - this makes unit tests harder to read, and performance isn't an issue. -->
2342
<Rule Id="CA1863" Action="None" />
43+
<!-- Call ConfigureAwait on tasks - you shouldn't do this in unit test libraries; XUnit has an opposite analyzer. -->
2444
<Rule Id="CA2007" Action="None" />
45+
<!-- Implement serialization constructors - false positive when building .NET Core. -->
2546
<Rule Id="CA2229" Action="None" />
47+
<!-- Use Uri instead of string parameters - strings are easier for testing. -->
2648
<Rule Id="CA2234" Action="None" />
49+
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core. -->
2750
<Rule Id="CA2237" Action="None" />
51+
<!-- Prefer generic overloads to using Type parameters - we do a lot of reflection work in Autofac that needs to be tested. -->
2852
<Rule Id="CA2263" Action="None" />
2953
</Rules>
3054
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
55+
<!-- Prefix local calls with this. -->
3156
<Rule Id="SA1101" Action="None" />
57+
<!-- Use built-in type alias. -->
3258
<Rule Id="SA1121" Action="None" />
59+
<!-- Use String.Empty instead of "". -->
3360
<Rule Id="SA1122" Action="None" />
61+
<!-- Enforce order of class members by member type - sometimes putting test classes/data by the test helps. -->
3462
<Rule Id="SA1201" Action="None" />
63+
<!-- Enforce order of class members by member visibility - sometimes putting test classes/data by the test helps. -->
3564
<Rule Id="SA1202" Action="None" />
65+
<!-- Enforce order of static vs. non-static members - sometimes putting test classes/data by the test helps. -->
3666
<Rule Id="SA1204" Action="None" />
67+
<!-- Fields can't start with underscore. -->
3768
<Rule Id="SA1309" Action="None" />
69+
<!-- Elements should be documented. -->
3870
<Rule Id="SA1600" Action="None" />
71+
<!-- Partial items should be documented. -->
3972
<Rule Id="SA1601" Action="None" />
73+
<!-- Enumeration items should be documented. -->
4074
<Rule Id="SA1602" Action="None" />
75+
<!-- Parameter should be documented. -->
4176
<Rule Id="SA1611" Action="None" />
77+
<!-- Parameter documentation must be in the right order. -->
4278
<Rule Id="SA1612" Action="None" />
79+
<!-- Return value must be documented. -->
4380
<Rule Id="SA1615" Action="None" />
81+
<!-- Generic type parameters must be documented. -->
4482
<Rule Id="SA1618" Action="None" />
83+
<!-- Don't copy/paste documentation. -->
4584
<Rule Id="SA1625" Action="None" />
46-
<Rule Id="SA1633" Action="None" />
85+
<!-- Private member is unused - tests for reflection require members that may not get used. -->
4786
<Rule Id="IDE0051" Action="None" />
87+
<!-- Private member assigned value never read - tests for reflection require values that may not get used. -->
4888
<Rule Id="IDE0052" Action="None" />
89+
<!-- Remove unused parameter - tests for reflection require parameters that may not get used. -->
4990
<Rule Id="IDE0060" Action="None" />
5091
</Rules>
5192
</RuleSet>

build/stylecop.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"licenseName": "MIT"
1010
},
1111
"xmlHeader": false
12+
},
13+
"orderingRules": {
14+
"usingDirectivesPlacement": "outsideNamespace"
1215
}
1316
}
1417
}

default.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
<Exec Command="dotnet build &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) /p:Version=$(Version)" />
5858
</Target>
5959
<Target Name="Package">
60-
<MakeDir Directories="$([System.IO.Path]::Combine($(PackageDirectory),%(PublishProject.Filename)))" />
61-
<Exec Command="dotnet pack &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) --output &quot;$(PackageDirectory)&quot; /p:Version=$(Version)" />
60+
<MakeDir Directories="$(PackageDirectory)" />
61+
<Exec Command="dotnet pack &quot;%(SourceProject.Identity)&quot; -c $(Configuration) --no-build --output &quot;$(PackageDirectory)&quot; /p:Version=$(Version)" />
6262
</Target>
6363
<Target Name="Test">
6464
<MakeDir Directories="$(LogDirectory)" />

src/Autofac.Extras.AggregateService/AggregateServiceGenerator.cs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,52 @@
55
using System.Reflection;
66
using Castle.DynamicProxy;
77

8-
namespace Autofac.Extras.AggregateService
8+
namespace Autofac.Extras.AggregateService;
9+
10+
/// <summary>
11+
/// Generate aggregate service instances from interface types.
12+
/// </summary>
13+
public static class AggregateServiceGenerator
914
{
15+
private static readonly ProxyGenerator _generator = new ProxyGenerator();
16+
1017
/// <summary>
11-
/// Generate aggregate service instances from interface types.
18+
/// Generate an aggregate service instance that will resolve its types from <paramref name="context"/>.
1219
/// </summary>
13-
public static class AggregateServiceGenerator
20+
/// <param name="context">The component context from where types will be resolved.</param>
21+
/// <typeparam name="TAggregateServiceInterface">The interface type for the aggregate service.</typeparam>
22+
/// <returns>The aggregate service instance.</returns>
23+
/// <exception cref="ArgumentException">Thrown if <typeparamref name="TAggregateServiceInterface"/> is not an interface.</exception>
24+
public static object CreateInstance<TAggregateServiceInterface>(IComponentContext context)
1425
{
15-
private static readonly ProxyGenerator Generator = new ProxyGenerator();
16-
17-
/// <summary>
18-
/// Generate an aggregate service instance that will resolve its types from <paramref name="context"/>.
19-
/// </summary>
20-
/// <param name="context">The component context from where types will be resolved.</param>
21-
/// <typeparam name="TAggregateServiceInterface">The interface type for the aggregate service.</typeparam>
22-
/// <returns>The aggregate service instance.</returns>
23-
/// <exception cref="ArgumentException">Thrown if <typeparamref name="TAggregateServiceInterface"/> is not an interface.</exception>
24-
public static object CreateInstance<TAggregateServiceInterface>(IComponentContext context)
26+
return CreateInstance(typeof(TAggregateServiceInterface), context);
27+
}
28+
29+
/// <summary>
30+
/// Generate an aggregate service instance that will resolve its types from <paramref name="context"/>.
31+
/// </summary>
32+
/// <param name="interfaceType">The interface type for the aggregate service.</param>
33+
/// <param name="context">The component context from where types will be resolved.</param>
34+
/// <returns>The aggregate service instance.</returns>
35+
/// <exception cref="ArgumentException">Thrown if <paramref name="interfaceType"/> is not an interface.</exception>
36+
public static object CreateInstance(Type interfaceType, IComponentContext context)
37+
{
38+
if (context == null)
2539
{
26-
return CreateInstance(typeof(TAggregateServiceInterface), context);
40+
throw new ArgumentNullException(nameof(context));
2741
}
2842

29-
/// <summary>
30-
/// Generate an aggregate service instance that will resolve its types from <paramref name="context"/>.
31-
/// </summary>
32-
/// <param name="interfaceType">The interface type for the aggregate service.</param>
33-
/// <param name="context">The component context from where types will be resolved.</param>
34-
/// <returns>The aggregate service instance.</returns>
35-
/// <exception cref="ArgumentException">Thrown if <paramref name="interfaceType"/> is not an interface.</exception>
36-
public static object CreateInstance(Type interfaceType, IComponentContext context)
43+
if (interfaceType == null)
3744
{
38-
if (context == null)
39-
{
40-
throw new ArgumentNullException(nameof(context));
41-
}
42-
43-
if (interfaceType == null)
44-
{
45-
throw new ArgumentNullException(nameof(interfaceType));
46-
}
47-
48-
if (!interfaceType.GetTypeInfo().IsInterface)
49-
{
50-
throw new ArgumentException(AggregateServicesResources.TypeMustBeInterface, nameof(interfaceType));
51-
}
52-
53-
var resolverInterceptor = new ResolvingInterceptor(interfaceType, context);
54-
return Generator.CreateInterfaceProxyWithoutTarget(interfaceType, resolverInterceptor);
45+
throw new ArgumentNullException(nameof(interfaceType));
5546
}
47+
48+
if (!interfaceType.GetTypeInfo().IsInterface)
49+
{
50+
throw new ArgumentException(AggregateServicesResources.TypeMustBeInterface, nameof(interfaceType));
51+
}
52+
53+
var resolverInterceptor = new ResolvingInterceptor(interfaceType, context);
54+
return _generator.CreateInterfaceProxyWithoutTarget(interfaceType, resolverInterceptor);
5655
}
5756
}

0 commit comments

Comments
 (0)