Skip to content

Instantly share code, notes, and snippets.

@usausa
Created April 5, 2024 07:25
Show Gist options
  • Save usausa/549ac12003ca61032268bb36d864dba1 to your computer and use it in GitHub Desktop.
Save usausa/549ac12003ca61032268bb36d864dba1 to your computer and use it in GitHub Desktop.
using Microsoft.Extensions.DependencyInjection;
public sealed class KeyedServiceProxy<T>
where T : notnull
{
private readonly IServiceProvider serviceProvider;
public KeyedServiceProxy(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
public T Get(object key) => serviceProvider.GetRequiredKeyedService<T>(key);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment