using Serilog;
using Splat;
using System.Collections.Generic;
using System.Linq;
namespace SPTInstaller.Helpers;
///
/// A helper class to handle simple service registration to Splat with constructor parameter injection
///
/// Splat only recognizes the registered types and doesn't account for interfaces :(
internal static class ServiceHelper
{
private static bool TryRegisterInstance(object[] parameters = null)
{
var instance = Activator.CreateInstance(typeof(T2), parameters);
if (instance != null)
{
Locator.CurrentMutable.RegisterConstant((T)instance);
return true;
}
return false;
}
///
/// Register a class as a service
///
/// class to register
public static void Register() where T : class => Register();
///
/// Register a class as a service by another type
///
/// type to register as
/// class to register
public static void Register() where T : class
{
var constructors = typeof(T2).GetConstructors();
foreach (var constructor in constructors)
{
var parmesan = constructor.GetParameters();
if (parmesan.Length == 0)
{
if (TryRegisterInstance()) return;
continue;
}
List