Skip to content

Commit 3f266a4

Browse files
committed
Fix S4136: reorder methods so overloads are adjacent.
1 parent c65baec commit 3f266a4

3 files changed

Lines changed: 81 additions & 80 deletions

File tree

src/Autofac/Core/Registration/ComponentRegistryBuilder.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,6 @@ public void Register(IComponentRegistration registration)
130130
_registeredServicesTracker.AddRegistration(registration, false);
131131
}
132132

133-
/// <inheritdoc/>
134-
public void RegisterServiceMiddleware(Service service, IResolveMiddleware middleware, MiddlewareInsertionMode insertionMode = MiddlewareInsertionMode.EndOfPhase)
135-
{
136-
if (service is null)
137-
{
138-
throw new ArgumentNullException(nameof(service));
139-
}
140-
141-
if (middleware is null)
142-
{
143-
throw new ArgumentNullException(nameof(middleware));
144-
}
145-
146-
_registeredServicesTracker.AddServiceMiddleware(service, middleware, insertionMode);
147-
}
148-
149133
/// <summary>
150134
/// Register a component.
151135
/// </summary>
@@ -162,6 +146,22 @@ public void Register(IComponentRegistration registration, bool preserveDefaults)
162146
_registeredServicesTracker.AddRegistration(registration, preserveDefaults);
163147
}
164148

149+
/// <inheritdoc/>
150+
public void RegisterServiceMiddleware(Service service, IResolveMiddleware middleware, MiddlewareInsertionMode insertionMode = MiddlewareInsertionMode.EndOfPhase)
151+
{
152+
if (service is null)
153+
{
154+
throw new ArgumentNullException(nameof(service));
155+
}
156+
157+
if (middleware is null)
158+
{
159+
throw new ArgumentNullException(nameof(middleware));
160+
}
161+
162+
_registeredServicesTracker.AddServiceMiddleware(service, middleware, insertionMode);
163+
}
164+
165165
/// <summary>
166166
/// Add a registration source that will provide registrations on-the-fly.
167167
/// </summary>

src/Autofac/RegistrationExtensions.Decorators.cs

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,6 @@ namespace Autofac;
1717
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "RegistrationBuilder is where all registration syntax lives.")]
1818
public static partial class RegistrationExtensions
1919
{
20-
/// <summary>
21-
/// Decorate all components implementing open generic service <paramref name="decoratedServiceType"/>.
22-
/// The <paramref name="fromKey"/> and <paramref name="toKey"/> parameters must be different values.
23-
/// </summary>
24-
/// <param name="builder">Container builder.</param>
25-
/// <param name="decoratorType">
26-
/// The type of the decorator. Must be an open generic type, and accept a parameter
27-
/// of type <paramref name="decoratedServiceType"/>, which will be set to the instance being decorated.
28-
/// </param>
29-
/// <param name="decoratedServiceType">Service type being decorated. Must be an open generic type.</param>
30-
/// <param name="fromKey">Service key or name associated with the components being decorated.</param>
31-
/// <param name="toKey">Service key or name given to the decorated components.</param>
32-
/// <returns>The decorator registration for continued configuration.</returns>
33-
public static IRegistrationBuilder<object, OpenGenericDecoratorActivatorData, DynamicRegistrationStyle>
34-
RegisterGenericDecorator(
35-
this ContainerBuilder builder,
36-
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type decoratorType,
37-
Type decoratedServiceType,
38-
object fromKey,
39-
object? toKey = null)
40-
{
41-
if (builder == null)
42-
{
43-
throw new ArgumentNullException(nameof(builder));
44-
}
45-
46-
if (decoratorType == null)
47-
{
48-
throw new ArgumentNullException(nameof(decoratorType));
49-
}
50-
51-
if (decoratedServiceType == null)
52-
{
53-
throw new ArgumentNullException(nameof(decoratedServiceType));
54-
}
55-
56-
return OpenGenericRegistrationExtensions.RegisterGenericDecorator(builder, decoratorType, decoratedServiceType, fromKey, toKey);
57-
}
5820

5921
/// <summary>
6022
/// Decorate all components implementing service <typeparamref name="TService"/>
@@ -275,6 +237,45 @@ public static void RegisterDecorator<TService>(
275237
builder.RegisterCallback(crb => crb.Register(decoratorRegistration));
276238
}
277239

240+
/// <summary>
241+
/// Decorate all components implementing open generic service <paramref name="decoratedServiceType"/>.
242+
/// The <paramref name="fromKey"/> and <paramref name="toKey"/> parameters must be different values.
243+
/// </summary>
244+
/// <param name="builder">Container builder.</param>
245+
/// <param name="decoratorType">
246+
/// The type of the decorator. Must be an open generic type, and accept a parameter
247+
/// of type <paramref name="decoratedServiceType"/>, which will be set to the instance being decorated.
248+
/// </param>
249+
/// <param name="decoratedServiceType">Service type being decorated. Must be an open generic type.</param>
250+
/// <param name="fromKey">Service key or name associated with the components being decorated.</param>
251+
/// <param name="toKey">Service key or name given to the decorated components.</param>
252+
/// <returns>The decorator registration for continued configuration.</returns>
253+
public static IRegistrationBuilder<object, OpenGenericDecoratorActivatorData, DynamicRegistrationStyle>
254+
RegisterGenericDecorator(
255+
this ContainerBuilder builder,
256+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type decoratorType,
257+
Type decoratedServiceType,
258+
object fromKey,
259+
object? toKey = null)
260+
{
261+
if (builder == null)
262+
{
263+
throw new ArgumentNullException(nameof(builder));
264+
}
265+
266+
if (decoratorType == null)
267+
{
268+
throw new ArgumentNullException(nameof(decoratorType));
269+
}
270+
271+
if (decoratedServiceType == null)
272+
{
273+
throw new ArgumentNullException(nameof(decoratedServiceType));
274+
}
275+
276+
return OpenGenericRegistrationExtensions.RegisterGenericDecorator(builder, decoratorType, decoratedServiceType, fromKey, toKey);
277+
}
278+
278279
/// <summary>
279280
/// Decorate all components implementing open generic service <paramref name="serviceType"/>.
280281
/// </summary>

src/Autofac/RegistrationExtensions.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,32 @@ public static IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistration
229229
return registration;
230230
}
231231

232+
/// <summary>
233+
/// Specify how a type from a scanned assembly provides metadata.
234+
/// </summary>
235+
/// <typeparam name="TLimit">Registration limit type.</typeparam>
236+
/// <typeparam name="TScanningActivatorData">Activator data type.</typeparam>
237+
/// <typeparam name="TRegistrationStyle">Registration style.</typeparam>
238+
/// <param name="registration">Registration to set service mapping on.</param>
239+
/// <param name="metadataKey">Key of the metadata item.</param>
240+
/// <param name="metadataValueMapping">A function retrieving the value of the item from the component type.</param>
241+
/// <returns>Registration builder allowing the registration to be configured.</returns>
242+
public static IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistrationStyle>
243+
WithMetadata<TLimit, TScanningActivatorData, TRegistrationStyle>(
244+
this IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistrationStyle> registration,
245+
string metadataKey,
246+
Func<Type, object> metadataValueMapping)
247+
where TScanningActivatorData : ScanningActivatorData
248+
{
249+
if (registration == null)
250+
{
251+
throw new ArgumentNullException(nameof(registration));
252+
}
253+
254+
return registration.WithMetadata(t =>
255+
new[] { new KeyValuePair<string, object?>(metadataKey, metadataValueMapping(t)) });
256+
}
257+
232258
/// <summary>
233259
/// Use the properties of an attribute (or interface implemented by an attribute) on the scanned type
234260
/// to provide metadata values.
@@ -266,32 +292,6 @@ public static IRegistrationBuilder<object, ScanningActivatorData, DynamicRegistr
266292
});
267293
}
268294

269-
/// <summary>
270-
/// Specify how a type from a scanned assembly provides metadata.
271-
/// </summary>
272-
/// <typeparam name="TLimit">Registration limit type.</typeparam>
273-
/// <typeparam name="TScanningActivatorData">Activator data type.</typeparam>
274-
/// <typeparam name="TRegistrationStyle">Registration style.</typeparam>
275-
/// <param name="registration">Registration to set service mapping on.</param>
276-
/// <param name="metadataKey">Key of the metadata item.</param>
277-
/// <param name="metadataValueMapping">A function retrieving the value of the item from the component type.</param>
278-
/// <returns>Registration builder allowing the registration to be configured.</returns>
279-
public static IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistrationStyle>
280-
WithMetadata<TLimit, TScanningActivatorData, TRegistrationStyle>(
281-
this IRegistrationBuilder<TLimit, TScanningActivatorData, TRegistrationStyle> registration,
282-
string metadataKey,
283-
Func<Type, object> metadataValueMapping)
284-
where TScanningActivatorData : ScanningActivatorData
285-
{
286-
if (registration == null)
287-
{
288-
throw new ArgumentNullException(nameof(registration));
289-
}
290-
291-
return registration.WithMetadata(t =>
292-
new[] { new KeyValuePair<string, object?>(metadataKey, metadataValueMapping(t)) });
293-
}
294-
295295
/// <summary>
296296
/// Set the policy used to find candidate constructors on the implementation type.
297297
/// </summary>

0 commit comments

Comments
 (0)