Skip to content

Use latest MS dependencies for each corresponding .net version #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Lamar.AspNetCoreTests.Bugs;

#if NET8_0_OR_GREATER
public class Bug_395_keyed_service_closed_generic_interface_registration_check
{
class ClassA {}
Expand Down Expand Up @@ -45,4 +46,5 @@ public void do_not_blow_up()
.ShouldNotBeNull();
}
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,24 @@
<ProjectReference Include="..\Lamar\Lamar.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="[8.0.0,10.0.0)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="[8.0.0,10.0.0)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="[8.0.0,10.0.0)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="[8.0.0,10.0.0)" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="[9.0.0,10.0.0)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="[9.0.0,10.0.0)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="[9.0.0,10.0.0)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="[9.0.0,10.0.0)" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="[8.0.0,9.0.0)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="[8.0.0,9.0.0)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="[8.0.0,9.0.0)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="[8.0.0,9.0.0)" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="[7.0.0,8.0.0)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="[7.0.0,8.0.0)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="[7.0.0,8.0.0)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="[7.0.0,8.0.0)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Lamar.Testing.IoC.Acceptance;

public class IKeyedServiceProvider_compliance
{
#region sample_adding_keyed_services
#if NET8_0_OR_GREATER

[Fact]
public void register_by_name_using_dot_net_core_syntax()
Expand Down Expand Up @@ -44,5 +44,5 @@ public void register_by_name_using_dot_net_core_syntax()
.ShouldNotBeSameAs(container.GetKeyedService<CWidget>("C3"));
}

#endregion
#endif
}
5 changes: 4 additions & 1 deletion src/Lamar/IServiceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

namespace Lamar;

public interface IServiceContext : IServiceProvider, IDisposable, IAsyncDisposable, IKeyedServiceProvider
public interface IServiceContext : IServiceProvider, IDisposable, IAsyncDisposable
#if NET8_0_OR_GREATER
, IKeyedServiceProvider
#endif
{
/// <summary>
/// Provides queryable access to the configured serviceType's and Instances of this Container.
Expand Down
5 changes: 3 additions & 2 deletions src/Lamar/IoC/Instances/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ internal IEnumerable<Assembly> ReferencedAssemblies()

public static Instance For(ServiceDescriptor service)
{
#if NET8_0_OR_GREATER
if (service.IsKeyedService)
{
var name = service.ServiceKey?.ToString();
Instance instance = null;

if (service.KeyedImplementationInstance != null)
{
instance = new ObjectInstance(service.ServiceType, service.KeyedImplementationInstance);
Expand All @@ -136,9 +138,8 @@ public static Instance For(ServiceDescriptor service)
if (name.IsNotEmpty()) instance.Name = name;

return instance;


}
#endif


if (service.ImplementationInstance is Instance i)
Expand Down
16 changes: 14 additions & 2 deletions src/Lamar/Lamar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@
<PackageReference Include="JasperFx.CodeGeneration" Version="3.7.0" />
<PackageReference Include="JasperFx.Core" Version="1.9.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
</ItemGroup>
</Project>
15 changes: 12 additions & 3 deletions src/Lamar/ServiceGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ private ServiceFamily buildFamilyForInstanceGroup(IServiceCollection services,

private ServiceFamily buildClosedGenericType(Type serviceType, IServiceCollection services)
{
var closed = services.Where(x => x.ServiceType == serviceType && (x.IsKeyedService
? !x.KeyedImplementationType.IsOpenGeneric()
: !x.ImplementationType.IsOpenGeneric()))
var closed = services.Where(x => x.ServiceType == serviceType && isKeyedServiceSupported(x))
.Select(Instance.For);

var templated = services
Expand All @@ -297,6 +295,17 @@ private ServiceFamily buildClosedGenericType(Type serviceType, IServiceCollectio
return new ServiceFamily(serviceType, DecoratorPolicies, instances);
}

private static bool isKeyedServiceSupported(ServiceDescriptor serviceDescriptor)
{
#if NET8_0_OR_GREATER
return serviceDescriptor.IsKeyedService
? !serviceDescriptor.KeyedImplementationType.IsOpenGeneric()
: !serviceDescriptor.ImplementationType.IsOpenGeneric();
#endif

return !serviceDescriptor.ImplementationType.IsOpenGeneric();
}

public IEnumerable<Instance> AllInstances()
{
var serviceFamilies = _families.Enumerate().Select(x => x.Value).Where(x => x != null).ToArray();
Expand Down
Loading