mirror of
https://github.com/AlexMacocian/SystemExtensions.git
synced 2026-07-15 14:19:29 +00:00
e6a06915cd
Codestyle fixes Setup CODEOWNERS Setup dependabot
27 lines
765 B
C#
27 lines
765 B
C#
using Slim.Resolvers;
|
|
|
|
namespace System.Configuration;
|
|
|
|
public sealed class LiveOptionsResolver : IDependencyResolver
|
|
{
|
|
private static readonly Type optionsType = typeof(LiveUpdateableOptionsWrapper<>);
|
|
|
|
public bool CanResolve(Type type)
|
|
{
|
|
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ILiveOptions<>))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public object Resolve(Slim.IServiceProvider serviceProvider, Type type)
|
|
{
|
|
var typedOptionsType = optionsType.MakeGenericType(type.GetGenericArguments());
|
|
var configurationManager = serviceProvider.GetService<IOptionsManager>();
|
|
|
|
return Activator.CreateInstance(typedOptionsType, configurationManager);
|
|
}
|
|
}
|