Skip to content

Commit 35f4474

Browse files
committed
Update style to match analyzers.
1 parent de6a847 commit 35f4474

File tree

7 files changed

+62
-67
lines changed

7 files changed

+62
-67
lines changed

bench/Autofac.Extensions.DependencyInjection.Bench/Autofac.Extensions.DependencyInjection.Bench.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<GenerateProgramFile>false</GenerateProgramFile>
77
<PlatformTarget>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</PlatformTarget>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9-
<AssemblyOriginatorKeyFile>../../Autofac.snk</AssemblyOriginatorKeyFile>
10-
<SignAssembly>true</SignAssembly>
119
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
1210
<PreserveCompilationContext>true</PreserveCompilationContext>
1311
<CodeAnalysisRuleSet>../../build/Test.ruleset</CodeAnalysisRuleSet>

bench/projects/Bench.AutofacApiServer/BenchProject.AutofacApiServer.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
2-
32
<PropertyGroup>
43
<TargetFramework>net8.0</TargetFramework>
54
<OutputType>Exe</OutputType>
@@ -12,16 +11,13 @@
1211
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
1312
<ImplicitUsings>enable</ImplicitUsings>
1413
</PropertyGroup>
15-
1614
<ItemGroup>
1715
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
1816
<PrivateAssets>all</PrivateAssets>
1917
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2018
</PackageReference>
2119
</ItemGroup>
22-
2320
<ItemGroup>
2421
<AdditionalFiles Include="..\..\..\build\stylecop.json" Link="stylecop.json" />
2522
</ItemGroup>
26-
2723
</Project>

src/Autofac.Extensions.DependencyInjection/AutofacChildLifetimeScopeConfigurationAdapter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public class AutofacChildLifetimeScopeConfigurationAdapter
1010
{
1111
private readonly List<Action<ContainerBuilder>> _configurationActions = new();
1212

13+
/// <summary>
14+
/// Gets the list of configuration actions to be executed on the <see cref="ContainerBuilder"/> for the child <see cref="ILifetimeScope"/>.
15+
/// </summary>
16+
public IReadOnlyList<Action<ContainerBuilder>> ConfigurationActions => _configurationActions;
17+
1318
/// <summary>
1419
/// Adds a configuration action that will be executed when the child <see cref="ILifetimeScope"/> is created.
1520
/// </summary>
@@ -24,9 +29,4 @@ public void Add(Action<ContainerBuilder> configurationAction)
2429

2530
_configurationActions.Add(configurationAction);
2631
}
27-
28-
/// <summary>
29-
/// Gets the list of configuration actions to be executed on the <see cref="ContainerBuilder"/> for the child <see cref="ILifetimeScope"/>.
30-
/// </summary>
31-
public IReadOnlyList<Action<ContainerBuilder>> ConfigurationActions => _configurationActions;
3232
}

src/Autofac.Extensions.DependencyInjection/AutofacChildLifetimeScopeServiceProviderFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace Autofac.Extensions.DependencyInjection;
1010
/// </summary>
1111
public class AutofacChildLifetimeScopeServiceProviderFactory : IServiceProviderFactory<AutofacChildLifetimeScopeConfigurationAdapter>
1212
{
13+
private static readonly Action<ContainerBuilder> FallbackConfigurationAction = builder => { };
1314
private readonly Action<ContainerBuilder> _containerConfigurationAction;
1415
private readonly ILifetimeScope _rootLifetimeScope;
15-
private static readonly Action<ContainerBuilder> FallbackConfigurationAction = builder => { };
1616

1717
/// <summary>
1818
/// Initializes a new instance of the <see cref="AutofacChildLifetimeScopeServiceProviderFactory"/> class.

src/Autofac.Extensions.DependencyInjection/AutofacServiceProvider.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public AutofacServiceProvider(ILifetimeScope lifetimeScope)
2929
_lifetimeScope = lifetimeScope;
3030
}
3131

32+
/// <summary>
33+
/// Gets the underlying instance of <see cref="ILifetimeScope" />.
34+
/// </summary>
35+
public ILifetimeScope LifetimeScope => _lifetimeScope;
36+
3237
/// <summary>
3338
/// Gets the service object of the specified type.
3439
/// </summary>
@@ -158,30 +163,6 @@ public bool IsKeyedService(Type serviceType, object? serviceKey)
158163
return _lifetimeScope.ResolveOptional(serviceType);
159164
}
160165

161-
/// <summary>
162-
/// Gets the underlying instance of <see cref="ILifetimeScope" />.
163-
/// </summary>
164-
public ILifetimeScope LifetimeScope => _lifetimeScope;
165-
166-
/// <summary>
167-
/// Releases unmanaged and - optionally - managed resources.
168-
/// </summary>
169-
/// <param name="disposing">
170-
/// <see langword="true" /> to release both managed and unmanaged resources;
171-
/// <see langword="false" /> to release only unmanaged resources.
172-
/// </param>
173-
protected virtual void Dispose(bool disposing)
174-
{
175-
if (!_disposed)
176-
{
177-
_disposed = true;
178-
if (disposing)
179-
{
180-
_lifetimeScope.Dispose();
181-
}
182-
}
183-
}
184-
185166
/// <summary>
186167
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
187168
/// </summary>
@@ -194,6 +175,7 @@ public void Dispose()
194175
/// <summary>
195176
/// Performs a dispose operation asynchronously.
196177
/// </summary>
178+
/// <returns>A task to await disposal.</returns>
197179
public async ValueTask DisposeAsync()
198180
{
199181
if (!_disposed)
@@ -203,4 +185,23 @@ public async ValueTask DisposeAsync()
203185
GC.SuppressFinalize(this);
204186
}
205187
}
188+
189+
/// <summary>
190+
/// Releases unmanaged and - optionally - managed resources.
191+
/// </summary>
192+
/// <param name="disposing">
193+
/// <see langword="true" /> to release both managed and unmanaged resources;
194+
/// <see langword="false" /> to release only unmanaged resources.
195+
/// </param>
196+
protected virtual void Dispose(bool disposing)
197+
{
198+
if (!_disposed)
199+
{
200+
_disposed = true;
201+
if (disposing)
202+
{
203+
_lifetimeScope.Dispose();
204+
}
205+
}
206+
}
206207
}

src/Autofac.Extensions.DependencyInjection/AutofacServiceScope.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace Autofac.Extensions.DependencyInjection;
1111
/// <seealso cref="IServiceScope" />
1212
internal class AutofacServiceScope : IServiceScope, IAsyncDisposable
1313
{
14-
private bool _disposed;
1514
private readonly AutofacServiceProvider _serviceProvider;
15+
private bool _disposed;
1616

1717
/// <summary>
1818
/// Initializes a new instance of the <see cref="AutofacServiceScope"/> class.
@@ -48,6 +48,16 @@ public void Dispose()
4848
GC.SuppressFinalize(this);
4949
}
5050

51+
/// <inheritdoc/>
52+
public async ValueTask DisposeAsync()
53+
{
54+
if (!_disposed)
55+
{
56+
_disposed = true;
57+
await _serviceProvider.DisposeAsync().ConfigureAwait(false);
58+
}
59+
}
60+
5161
/// <summary>
5262
/// Releases unmanaged and - optionally - managed resources.
5363
/// </summary>
@@ -66,14 +76,4 @@ protected virtual void Dispose(bool disposing)
6676
}
6777
}
6878
}
69-
70-
/// <inheritdoc/>
71-
public async ValueTask DisposeAsync()
72-
{
73-
if (!_disposed)
74-
{
75-
_disposed = true;
76-
await _serviceProvider.DisposeAsync().ConfigureAwait(false);
77-
}
78-
}
7979
}

src/Autofac.Extensions.DependencyInjection/KeyedServiceMiddleware.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,16 @@ internal class KeyedServiceMiddleware : IResolveMiddleware
1717
// for injection into a constructor. This is similar to the
1818
// Autofac [KeyFilter] attribute.
1919
private static readonly Parameter FromKeyedServicesParameter = new ResolvedParameter(
20-
(p, c) =>
21-
{
22-
var filter = p.GetCustomAttributes<FromKeyedServicesAttribute>(true).FirstOrDefault();
23-
return filter is not null && filter.CanResolveParameter(p, c);
24-
},
25-
(p, c) =>
26-
{
27-
var filter = p.GetCustomAttributes<FromKeyedServicesAttribute>(true).First();
28-
return filter.ResolveParameter(p, c);
29-
});
30-
31-
/// <summary>
32-
/// Gets a single instance of this middleware that does not add the keyed services parameter.
33-
/// </summary>
34-
public static KeyedServiceMiddleware InstanceWithoutFromKeyedServicesParameter { get; } = new(addFromKeyedServiceParameter: false);
35-
36-
/// <summary>
37-
/// Gets a single instance of this middleware that adds the keyed services parameter.
38-
/// </summary>
39-
public static KeyedServiceMiddleware InstanceWithFromKeyedServicesParameter { get; } = new(addFromKeyedServiceParameter: true);
20+
(p, c) =>
21+
{
22+
var filter = p.GetCustomAttributes<FromKeyedServicesAttribute>(true).FirstOrDefault();
23+
return filter is not null && filter.CanResolveParameter(p, c);
24+
},
25+
(p, c) =>
26+
{
27+
var filter = p.GetCustomAttributes<FromKeyedServicesAttribute>(true).First();
28+
return filter.ResolveParameter(p, c);
29+
});
4030

4131
private readonly bool _addFromKeyedServiceParameter;
4232

@@ -49,6 +39,16 @@ public KeyedServiceMiddleware(bool addFromKeyedServiceParameter)
4939
_addFromKeyedServiceParameter = addFromKeyedServiceParameter;
5040
}
5141

42+
/// <summary>
43+
/// Gets a single instance of this middleware that does not add the keyed services parameter.
44+
/// </summary>
45+
public static KeyedServiceMiddleware InstanceWithoutFromKeyedServicesParameter { get; } = new(addFromKeyedServiceParameter: false);
46+
47+
/// <summary>
48+
/// Gets a single instance of this middleware that adds the keyed services parameter.
49+
/// </summary>
50+
public static KeyedServiceMiddleware InstanceWithFromKeyedServicesParameter { get; } = new(addFromKeyedServiceParameter: true);
51+
5252
/// <inheritdoc />
5353
public PipelinePhase Phase => PipelinePhase.Activation;
5454

0 commit comments

Comments
 (0)