Dependency Injection extensions

This commit is contained in:
Alexandru Macocian
2021-07-10 10:59:27 +03:00
parent 5aaa0d318a
commit 7a764a5929
40 changed files with 1410 additions and 8 deletions
@@ -0,0 +1,26 @@
using Slim.Resolvers;
namespace System.Extensions.Configuration
{
public sealed class LiveUpdateableOptionsResolver : IDependencyResolver
{
private static readonly Type optionsType = typeof(LiveUpdateableOptionsWrapper<>);
public bool CanResolve(Type type)
{
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ILiveUpdateableOptions<>))
{
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);
}
}
}