Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
358 changes: 228 additions & 130 deletions .editorconfig

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions build/Source.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,39 @@
<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" />
<!-- Avoid excessive inheritance (must be explicitly enabled). -->
<Rule Id="CA1501" Action="Warning" />
<!-- Avoid excessive complexity (must be explicitly enabled). -->
<Rule Id="CA1502" Action="Warning" />
<!-- Avoid unmaintainable code (must be explicitly enabled). -->
<Rule Id="CA1505" Action="Warning" />
<!-- Avoid excessive class coupling (must be explicitly enabled). -->
<Rule Id="CA1506" Action="Warning" />
<!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. -->
<Rule Id="CA1510" Action="None" />
<!-- Use ArgumentOutOfRangeException.ThrowIfNegative - this isn't available until we stop targeting anything below net8.0. -->
<Rule Id="CA1512" Action="None" />
<!-- Use ObjectDisposedException.ThrowIf - this isn't available until we stop targeting anything below net8.0. -->
<Rule Id="CA1513" 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" />
<!-- Implement serialization constructors - false positive when building .NET Core -->
<!-- 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. -->
<Rule Id="CA1863" 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 -->
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core. -->
<Rule Id="CA2237" Action="None" />
<!-- Prefer generic overloads to using Type parameters - many aren't available in earlier frameworks; and we do a lot of reflection work in Autofac. -->
<Rule Id="CA2263" Action="None" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<!-- Prefix local calls with this -->
<!-- Prefix local calls with this. -->
<Rule Id="SA1101" Action="None" />
<!-- Use built-in type alias -->
<!-- Use built-in type alias. -->
<Rule Id="SA1121" Action="None" />
<!-- Use String.Empty instead of "" -->
<!-- Use String.Empty instead of "". -->
<Rule Id="SA1122" Action="None" />
<!-- Using statements must be inside a namespace -->
<Rule Id="SA1200" Action="None" />
<!-- Fields can't start with underscore -->
<!-- Fields can't start with underscore. -->
<Rule Id="SA1309" Action="None" />
</Rules>
</RuleSet>
47 changes: 44 additions & 3 deletions build/Test.ruleset
Original file line number Diff line number Diff line change
@@ -1,51 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac test assemblies." ToolsVersion="16.0">
<?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">
<!-- Avoid excessive parameters on generic types (must be explicitly enabled). -->
<Rule Id="CA1005" Action="Warning" />
<!-- Don't catch general exceptions - test scenarios sometimes require general exception handling. -->
<Rule Id="CA1031" Action="None" />
<!-- Implement standard exception constructors - not all of the exception constructors (e.g., parameterless) are desired in our system. -->
<Rule Id="CA1032" Action="None" />
<!-- Avoid empty interfaces - in unit tests for service resolution, this happens a lot. -->
<Rule Id="CA1040" Action="None" />
<!-- Do not pass literals as localized parameters - tests don't need to localize. -->
<Rule Id="CA1303" Action="None" />
<!-- Avoid excessive inheritance (must be explicitly enabled). -->
<Rule Id="CA1501" Action="Warning" />
<!-- Avoid excessive complexity (must be explicitly enabled). -->
<Rule Id="CA1502" Action="Warning" />
<!-- Avoid unmaintainable code (must be explicitly enabled). -->
<Rule Id="CA1505" Action="Warning" />
<!-- Avoid excessive class coupling (must be explicitly enabled). -->
<Rule Id="CA1506" Action="Warning" />
<!-- Use ArgumentNullException.ThrowIfNull - this isn't available until we stop targeting netstandard. -->
<Rule Id="CA1510" Action="None" />
<!-- Make API types internal - causes problems with tests and test assemblies. -->
<Rule Id="CA1515" Action="None" />
<!-- Remove the underscores from member name - unit test scenarios may use underscores. -->
<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" />
<!-- Internal class that appears to never be instantiated - lots of false positives here because they're test stubs created by Autofac registrations. -->
<Rule Id="CA1812" 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" />
<!-- Seal internal types for performance - in tests we don't really care and it gets painful to enforce. -->
<Rule Id="CA1852" Action="None" />
<!-- Prefer static readonly fields over constant array arguments - constant array arguments happen a lot in unit tests for assertions and test setup. -->
<Rule Id="CA1861" Action="None" />
<!-- Cache a CompositeFormat object for use in String.Format - this makes unit tests harder to read, and performance isn't an issue. -->
<Rule Id="CA1863" Action="None" />
<!-- Call ConfigureAwait on tasks - you shouldn't do this in unit test libraries; XUnit has an opposite analyzer. -->
<Rule Id="CA2007" Action="None" />
<!-- Implement serialization constructors - false positive when building .NET Core. -->
<Rule Id="CA2229" Action="None" />
<!-- Use Uri instead of string parameters - strings are easier for testing. -->
<Rule Id="CA2234" Action="None" />
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core. -->
<Rule Id="CA2237" Action="None" />
<!-- Prefer generic overloads to using Type parameters - we do a lot of reflection work in Autofac that needs to be tested. -->
<Rule Id="CA2263" 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" />
<!-- Enforce order of class members by member type - sometimes putting test classes/data by the test helps. -->
<Rule Id="SA1201" Action="None" />
<!-- Enforce order of class members by member visibility - sometimes putting test classes/data by the test helps. -->
<Rule Id="SA1202" Action="None" />
<!-- Enforce order of static vs. non-static members - sometimes putting test classes/data by the test helps. -->
<Rule Id="SA1204" Action="None" />
<!-- Fields can't start with underscore. -->
<Rule Id="SA1309" Action="None" />
<!-- Elements should be documented. -->
<Rule Id="SA1600" Action="None" />
<!-- Partial items should be documented. -->
<Rule Id="SA1601" Action="None" />
<!-- Enumeration items should be documented. -->
<Rule Id="SA1602" Action="None" />
<!-- Parameter should be documented. -->
<Rule Id="SA1611" Action="None" />
<!-- Parameter documentation must 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" />
<Rule Id="SA1633" 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>
3 changes: 3 additions & 0 deletions build/stylecop.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"licenseName": "MIT"
},
"xmlHeader": false
},
"orderingRules": {
"usingDirectivesPlacement": "outsideNamespace"
}
}
}
4 changes: 2 additions & 2 deletions default.proj
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<Exec Command="dotnet build &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) /p:Version=$(Version)" />
</Target>
<Target Name="Package">
<MakeDir Directories="$([System.IO.Path]::Combine($(PackageDirectory),%(PublishProject.Filename)))" />
<Exec Command="dotnet pack &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) --output &quot;$(PackageDirectory)&quot; /p:Version=$(Version)" />
<MakeDir Directories="$(PackageDirectory)" />
<Exec Command="dotnet pack &quot;%(SourceProject.Identity)&quot; -c $(Configuration) --no-build --output &quot;$(PackageDirectory)&quot; /p:Version=$(Version)" />
</Target>
<Target Name="Test">
<MakeDir Directories="$(LogDirectory)" />
Expand Down
77 changes: 38 additions & 39 deletions src/Autofac.Extras.AggregateService/AggregateServiceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,52 @@
using System.Reflection;
using Castle.DynamicProxy;

namespace Autofac.Extras.AggregateService
namespace Autofac.Extras.AggregateService;

/// <summary>
/// Generate aggregate service instances from interface types.
/// </summary>
public static class AggregateServiceGenerator
{
private static readonly ProxyGenerator _generator = new ProxyGenerator();

/// <summary>
/// Generate aggregate service instances from interface types.
/// Generate an aggregate service instance that will resolve its types from <paramref name="context"/>.
/// </summary>
public static class AggregateServiceGenerator
/// <param name="context">The component context from where types will be resolved.</param>
/// <typeparam name="TAggregateServiceInterface">The interface type for the aggregate service.</typeparam>
/// <returns>The aggregate service instance.</returns>
/// <exception cref="ArgumentException">Thrown if <typeparamref name="TAggregateServiceInterface"/> is not an interface.</exception>
public static object CreateInstance<TAggregateServiceInterface>(IComponentContext context)
{
private static readonly ProxyGenerator Generator = new ProxyGenerator();

/// <summary>
/// Generate an aggregate service instance that will resolve its types from <paramref name="context"/>.
/// </summary>
/// <param name="context">The component context from where types will be resolved.</param>
/// <typeparam name="TAggregateServiceInterface">The interface type for the aggregate service.</typeparam>
/// <returns>The aggregate service instance.</returns>
/// <exception cref="ArgumentException">Thrown if <typeparamref name="TAggregateServiceInterface"/> is not an interface.</exception>
public static object CreateInstance<TAggregateServiceInterface>(IComponentContext context)
return CreateInstance(typeof(TAggregateServiceInterface), context);
}

/// <summary>
/// Generate an aggregate service instance that will resolve its types from <paramref name="context"/>.
/// </summary>
/// <param name="interfaceType">The interface type for the aggregate service.</param>
/// <param name="context">The component context from where types will be resolved.</param>
/// <returns>The aggregate service instance.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="interfaceType"/> is not an interface.</exception>
public static object CreateInstance(Type interfaceType, IComponentContext context)
{
if (context == null)
{
return CreateInstance(typeof(TAggregateServiceInterface), context);
throw new ArgumentNullException(nameof(context));
}

/// <summary>
/// Generate an aggregate service instance that will resolve its types from <paramref name="context"/>.
/// </summary>
/// <param name="interfaceType">The interface type for the aggregate service.</param>
/// <param name="context">The component context from where types will be resolved.</param>
/// <returns>The aggregate service instance.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="interfaceType"/> is not an interface.</exception>
public static object CreateInstance(Type interfaceType, IComponentContext context)
if (interfaceType == null)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

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

if (!interfaceType.GetTypeInfo().IsInterface)
{
throw new ArgumentException(AggregateServicesResources.TypeMustBeInterface, nameof(interfaceType));
}

var resolverInterceptor = new ResolvingInterceptor(interfaceType, context);
return Generator.CreateInterfaceProxyWithoutTarget(interfaceType, resolverInterceptor);
throw new ArgumentNullException(nameof(interfaceType));
}

if (!interfaceType.GetTypeInfo().IsInterface)
{
throw new ArgumentException(AggregateServicesResources.TypeMustBeInterface, nameof(interfaceType));
}

var resolverInterceptor = new ResolvingInterceptor(interfaceType, context);
return _generator.CreateInterfaceProxyWithoutTarget(interfaceType, resolverInterceptor);
}
}
Loading
Loading