Skip to content

Commit 030a1bf

Browse files
committed
Fixed framework upgrade issues.
1 parent df0a7ac commit 030a1bf

File tree

5 files changed

+20
-47
lines changed

5 files changed

+20
-47
lines changed

DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ServiceCollectionServiceProvider.Net6.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

DependencyInjection/src/AppCoreNet.Extensions.DependencyInjection.Abstractions/ServiceCollectionServiceProvider.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace AppCoreNet.Extensions.DependencyInjection;
1212
/// <summary>
1313
/// Internal service provider which resolves services from an <see cref="IServiceCollection"/>.
1414
/// </summary>
15-
internal sealed partial class ServiceCollectionServiceProvider : IServiceProvider
15+
internal sealed partial class ServiceCollectionServiceProvider : IServiceProvider, IServiceProviderIsService
1616
{
1717
private readonly IServiceCollection _services;
1818
private readonly Dictionary<Type, object> _additionalServices = new();
@@ -27,6 +27,23 @@ public void AddService(Type serviceType, object instance)
2727
_additionalServices.Add(serviceType, instance);
2828
}
2929

30+
public bool IsService(Type serviceType)
31+
{
32+
if (serviceType == typeof(IServiceProvider) || serviceType == typeof(IServiceProviderIsService))
33+
return true;
34+
35+
if (_additionalServices.TryGetValue(serviceType, out object? _))
36+
return true;
37+
38+
if (serviceType.IsGenericType && serviceType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
39+
return true;
40+
41+
return _services.Any(
42+
sd => sd.ServiceType == serviceType
43+
|| (serviceType.IsGenericType
44+
&& sd.ServiceType == serviceType.GetGenericTypeDefinition()));
45+
}
46+
3047
private IEnumerable<object> GetServices(Type serviceType)
3148
{
3249
object ServiceFactory(ServiceDescriptor serviceDescriptor)

DependencyInjection/test/AppCoreNet.Extensions.DependencyInjection.AssemblyExtensions.Tests/AssemblyServicesDescriptorResolverTests.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ public void FiltersNonDerivableGenericTypes()
3535
contractType,
3636
typeof(ContractImpl2),
3737
ServiceLifetime.Transient),
38-
#if !NET8_0_OR_GREATER
39-
});
40-
#else
4138
},
4239
o =>
4340
o.Excluding(sd => sd.KeyedImplementationFactory)
4441
.Excluding(sd => sd.KeyedImplementationType)
4542
.Excluding(sd => sd.KeyedImplementationInstance));
46-
#endif
4743
}
4844

4945
[Fact]
@@ -81,15 +77,11 @@ public void ClosesOpenGenericInterfaceForClosedGenerics()
8177
closedContractType,
8278
typeof(ContractImpl2String),
8379
ServiceLifetime.Transient),
84-
#if !NET8_0_OR_GREATER
85-
});
86-
#else
8780
},
8881
o =>
8982
o.Excluding(sd => sd.KeyedImplementationFactory)
9083
.Excluding(sd => sd.KeyedImplementationType)
9184
.Excluding(sd => sd.KeyedImplementationInstance));
92-
#endif
9385
}
9486

9587
[Fact]

Hosting/test/AppCoreNet.Extensions.Hosting.Plugins.TestPlugin/AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
55
<Description>Plugin1 Description</Description>
66
<Copyright>Plugin1 Copyright</Copyright>
77
<IsTestProject>false</IsTestProject>

Hosting/test/AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2/AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
55
<Description>Plugin2 Description</Description>
66
<Copyright>Plugin2 Copyright</Copyright>
77
<IsTestProject>false</IsTestProject>

0 commit comments

Comments
 (0)