Skip to content

Commit f1b6d9b

Browse files
authored
Fix service scope validation compatibility with Microsoft DI (#336)
* fix scope for some services to pass the Ms DI's validation * Install all required versions explicitly
1 parent 6a37bcc commit f1b6d9b

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

.github/workflows/build-pr-ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ jobs:
1212
fetch-depth: 0
1313
- name: Setup .NET Core
1414
uses: actions/setup-dotnet@v4
15-
with: # NOTE: we don't need to install 6.x, 8.x and 9.x cause they are included in windows-latest(windows-2022) image.
16-
dotnet-version: 7.x
15+
with: # Install all required versions explicitly, since some frameworks may be missing from the image if they have been removed due to end of support.
16+
dotnet-version: |
17+
6.0.x
18+
7.0.x
19+
8.0.x
20+
9.0.x
1721
1822
- name: Build Reason
1923
run: "echo ref: ${{github.ref}} event: ${{github.event_name}}"

src/AspectCore.Extensions.DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ internal static IServiceCollection TryAddDynamicProxyServices(this IServiceColle
5353
services.TryAddScoped<IAspectActivatorFactory, AspectActivatorFactory>();
5454
services.TryAddScoped<IProxyGenerator, ProxyGenerator>();
5555
services.TryAddScoped<IParameterInterceptorSelector, ParameterInterceptorSelector>();
56+
services.TryAddScoped<IInterceptorCollector, InterceptorCollector>();
57+
services.TryAddScoped<IAspectBuilderFactory, AspectBuilderFactory>();
5658

57-
services.TryAddSingleton<IInterceptorCollector, InterceptorCollector>();
5859
services.TryAddSingleton<IAspectValidatorBuilder, AspectValidatorBuilder>();
59-
services.TryAddSingleton<IAspectBuilderFactory, AspectBuilderFactory>();
6060
services.TryAddSingleton<IProxyTypeGenerator, ProxyTypeGenerator>();
6161
services.TryAddSingleton<IAspectCachingProvider, AspectCachingProvider>();
6262

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Xunit;
3+
4+
namespace AspectCore.Extensions.DependencyInjection.Test;
5+
6+
public class ServiceCollectionBuildExtensionsTests
7+
{
8+
[Fact]
9+
public void BuildDynamicProxyProvider_Validate()
10+
{
11+
var services = new ServiceCollection();
12+
var provider = services.BuildDynamicProxyProvider(new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true });
13+
Assert.NotNull(provider);
14+
}
15+
}

0 commit comments

Comments
 (0)