mirror of
https://github.com/FalloutCollaborationProject/FCP-Mod-Updater.git
synced 2026-07-27 17:04:05 -07:00
21 lines
946 B
C#
21 lines
946 B
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Spectre.Console.Cli;
|
|
|
|
namespace FCPModUpdater.Infrastructure;
|
|
|
|
// Used to hook up Spectre.Cli to Dependency Injection
|
|
|
|
public sealed class TypeRegistrar(IServiceCollection services) : ITypeRegistrar
|
|
{
|
|
public ITypeResolver Build() => new TypeResolver(services.BuildServiceProvider());
|
|
public void Register(Type service, Type implementation) => services.AddSingleton(service, implementation);
|
|
public void RegisterInstance(Type service, object implementation) => services.AddSingleton(service, implementation);
|
|
public void RegisterLazy(Type service, Func<object> factory) => services.AddSingleton(service, _ => factory());
|
|
}
|
|
|
|
internal sealed class TypeResolver(IServiceProvider provider) : ITypeResolver, IDisposable
|
|
{
|
|
public object? Resolve(Type? type) => type is null ? null : provider.GetService(type);
|
|
public void Dispose() => (provider as IDisposable)?.Dispose();
|
|
}
|