Skip to content

Commit

Permalink
Enabling keyed services for .NET 6 & 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Dec 14, 2023
1 parent 0516eac commit 8ef1d78
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Lamar.Testing.IoC.Acceptance;

#if NET8_0_OR_GREATER

public class IKeyedServiceProvider_compliance
{
#region sample_adding_keyed_services
Expand Down Expand Up @@ -46,4 +46,3 @@ public void register_by_name_using_dot_net_core_syntax()

#endregion
}
#endif
7 changes: 1 addition & 6 deletions src/Lamar/IServiceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@

namespace Lamar;

public interface IServiceContext : IServiceProvider, IDisposable, IAsyncDisposable

#if NET8_0_OR_GREATER
,IKeyedServiceProvider
#endif

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

public static Instance For(ServiceDescriptor service)
{
#if NET8_0_OR_GREATER
if (service.IsKeyedService)
{
var name = service.ServiceKey?.ToString();
Expand Down Expand Up @@ -140,7 +139,7 @@ public static Instance For(ServiceDescriptor service)


}
#endif


if (service.ImplementationInstance is Instance i)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Lamar/IoC/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ public Lazy<T> LazyFor<T>()
{
return new Lazy<T>(GetInstance<T>);
}

#if NET8_0_OR_GREATER

public object GetKeyedService(Type serviceType, object serviceKey)
{
return TryGetInstance(serviceType, serviceKey.ToString());
Expand All @@ -484,5 +483,4 @@ public object GetRequiredKeyedService(Type serviceType, object serviceKey)
{
return GetInstance(serviceType, serviceKey.ToString());
}
#endif
}

0 comments on commit 8ef1d78

Please sign in to comment.