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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"netcoreapp",
"netstandard",
"notnull",
"parameterless",
"paramref",
"startable",
"subclassing",
Expand Down
36 changes: 8 additions & 28 deletions build/Source.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<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. -->
Expand All @@ -26,35 +34,7 @@
<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" />
<!-- 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. -->
<Rule Id="SA1309" Action="None" />
<!-- Suppressions must have a justification. -->
<Rule Id="SA1404" 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" />
<!-- Exception documentation must not be empty. -->
<Rule Id="SA1627" Action="None" />
<!-- Enable XML documentation output. -->
<Rule Id="SA1652" Action="None" />
</Rules>
</RuleSet>
36 changes: 18 additions & 18 deletions build/Test.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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. -->
Expand All @@ -10,6 +12,14 @@
<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" />
<!-- Remove the underscores from member name - unit test scenarios may use underscores. -->
Expand Down Expand Up @@ -44,28 +54,22 @@
<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. -->
<!-- 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. -->
<!-- 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 constantand static members. -->
<Rule Id="SA1203" Action="None" />
<!-- Enforce order of static vs. non-static members. -->
<!-- Enforce order of static vs. non-static members - sometimes putting test classes/data by the test helps. -->
<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. -->
<Rule Id="SA1309" Action="None" />
<!-- Suppressions must have a justification. -->
<Rule Id="SA1404" Action="None" />
<!-- Elements should be documented. -->
<Rule Id="SA1600" Action="None" />
<!-- Enuemration items should be documented. -->
<!-- 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. -->
Expand All @@ -74,10 +78,6 @@
<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. -->
Expand Down
4 changes: 2 additions & 2 deletions src/Autofac/Builder/BuildCallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Autofac.Builder;
/// </summary>
internal static class BuildCallbackManager
{
private static readonly TypedService CallbackServiceType = new(typeof(BuildCallbackService));

private const string BuildCallbacksExecutedKey = nameof(BuildCallbacksExecutedKey);

private static readonly TypedService CallbackServiceType = new(typeof(BuildCallbackService));

/// <summary>
/// Executes the newly-registered build callbacks for a given scope/container..
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Autofac/Builder/IHideObjectMembers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IHideObjectMembers
/// Standard System.Object member.
/// </summary>
/// <returns>Standard result.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Override for standard method to add attributes.")]
[EditorBrowsable(EditorBrowsableState.Never)]
Type GetType();

Expand Down
13 changes: 6 additions & 7 deletions src/Autofac/Builder/IRegistrationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace Autofac.Builder;
/// <summary>
/// Data structure used to construct registrations.
/// </summary>
/// <typeparam name="TLimit">The most specific type to which instances of the registration
/// can be cast.</typeparam>
/// <typeparam name="TLimit">The most specific type to which instances of the registration can be cast.</typeparam>
/// <typeparam name="TActivatorData">Activator builder type.</typeparam>
/// <typeparam name="TRegistrationStyle">Registration style type.</typeparam>
public interface IRegistrationBuilder<out TLimit, out TActivatorData, out TRegistrationStyle>
Expand Down Expand Up @@ -157,8 +156,8 @@ IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService>()
/// Configure the services that the component will provide. The generic parameter(s) to As()
/// will be exposed as TypedService instances.
/// </summary>
/// <typeparam name="TService1">Service type.</typeparam>
/// <typeparam name="TService2">Service type.</typeparam>
/// <typeparam name="TService1">First service type.</typeparam>
/// <typeparam name="TService2">Second service type.</typeparam>
/// <returns>A registration builder allowing further configuration of the component.</returns>
IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, TService2>()
where TService1 : notnull
Expand All @@ -168,9 +167,9 @@ IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, T
/// Configure the services that the component will provide. The generic parameter(s) to As()
/// will be exposed as TypedService instances.
/// </summary>
/// <typeparam name="TService1">Service type.</typeparam>
/// <typeparam name="TService2">Service type.</typeparam>
/// <typeparam name="TService3">Service type.</typeparam>
/// <typeparam name="TService1">First service type.</typeparam>
/// <typeparam name="TService2">Second service type.</typeparam>
/// <typeparam name="TService3">Third service type.</typeparam>
/// <returns>A registration builder allowing further configuration of the component.</returns>
IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, TService2, TService3>()
where TService1 : notnull
Expand Down
3 changes: 3 additions & 0 deletions src/Autofac/Builder/MetadataConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class MetadataConfiguration<TMetadata>
/// <typeparam name="TProperty">The type of the property.</typeparam>
/// <param name="propertyAccessor">An expression that accesses the property to set.</param>
/// <param name="value">The property value to set.</param>
/// <returns>
/// The current <see cref="MetadataConfiguration{TMetadata}"/> for continued configuration.
/// </returns>
public MetadataConfiguration<TMetadata> For<TProperty>(Expression<Func<TMetadata, TProperty>> propertyAccessor, TProperty value)
{
if (propertyAccessor == null)
Expand Down
6 changes: 3 additions & 3 deletions src/Autofac/Builder/ReflectionActivatorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Autofac.Builder;
/// </summary>
public class ReflectionActivatorData
{
private static readonly IConstructorFinder DefaultConstructorFinder = new DefaultConstructorFinder();
private static readonly IConstructorSelector DefaultConstructorSelector = new MostParametersConstructorSelector();

private Type _implementer = default!;
private IConstructorFinder _constructorFinder;
private IConstructorSelector _constructorSelector;

private static readonly IConstructorFinder DefaultConstructorFinder = new DefaultConstructorFinder();
private static readonly IConstructorSelector DefaultConstructorSelector = new MostParametersConstructorSelector();

/// <summary>
/// Initializes a new instance of the <see cref="ReflectionActivatorData"/> class.
/// </summary>
Expand Down
9 changes: 7 additions & 2 deletions src/Autofac/Builder/RegistrationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public static IRegistrationBuilder<T, SimpleActivatorData, SingleRegistrationSty
/// <summary>
/// Creates a registration builder for the provided delegate.
/// </summary>
/// <param name="delegate">Delegate to register.</param>
/// <param name="limitType">Most specific type return value of delegate can be cast to.</param>
/// <param name="delegate">Delegate to register.</param>
/// <returns>A registration builder.</returns>
public static IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle> ForDelegate(Type limitType, Func<IComponentContext, IEnumerable<Parameter>, object> @delegate)
{
Expand Down Expand Up @@ -101,6 +101,9 @@ public static IRegistrationBuilder<object, ConcreteReflectionActivatorData, Sing
/// Create an <see cref='IComponentRegistration'/> from a <see cref='RegistrationBuilder'/>.
/// There is no need to call this method when registering components through a <see cref="ContainerBuilder"/>.
/// </summary>
/// <typeparam name="TLimit">The most specific type to which instances of the registration can be cast.</typeparam>
/// <typeparam name="TActivatorData">Activator builder type.</typeparam>
/// <typeparam name="TSingleRegistrationStyle">Registration style for individual components.</typeparam>
/// <remarks>
/// When called on the result of one of the <see cref='ContainerBuilder'/> methods,
/// the returned registration will be different from the one the builder itself registers
Expand Down Expand Up @@ -253,7 +256,9 @@ public static IComponentRegistration CreateRegistration(
/// Register a component in the component registry. This helper method is necessary
/// in order to execute OnRegistered hooks and respect PreserveDefaults.
/// </summary>
/// <remarks>Hoping to refactor this out.</remarks>
/// <typeparam name="TLimit">The most specific type to which instances of the registration can be cast.</typeparam>
/// <typeparam name="TActivatorData">Activator builder type.</typeparam>
/// <typeparam name="TSingleRegistrationStyle">Registration style for individual components.</typeparam>
/// <param name="cr">Component registry to make registration in.</param>
/// <param name="builder">Registration builder with data for new registration.</param>
public static void RegisterSingleComponent<TLimit, TActivatorData, TSingleRegistrationStyle>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TServ
/// Configure the services that the component will provide. The generic parameter(s) to As()
/// will be exposed as TypedService instances.
/// </summary>
/// <typeparam name="TService1">Service type.</typeparam>
/// <typeparam name="TService2">Service type.</typeparam>
/// <typeparam name="TService1">First service type.</typeparam>
/// <typeparam name="TService2">Second service type.</typeparam>
/// <returns>A registration builder allowing further configuration of the component.</returns>
public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, TService2>()
where TService1 : notnull
Expand All @@ -252,9 +252,9 @@ public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TServ
/// Configure the services that the component will provide. The generic parameter(s) to As()
/// will be exposed as TypedService instances.
/// </summary>
/// <typeparam name="TService1">Service type.</typeparam>
/// <typeparam name="TService2">Service type.</typeparam>
/// <typeparam name="TService3">Service type.</typeparam>
/// <typeparam name="TService1">First service type.</typeparam>
/// <typeparam name="TService2">Second service type.</typeparam>
/// <typeparam name="TService3">Third service type.</typeparam>
/// <returns>A registration builder allowing further configuration of the component.</returns>
public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> As<TService1, TService2, TService3>()
where TService1 : notnull
Expand Down
Loading