using System;
using System.Linq;
using xExceptions.Models;
using xExceptions.Constants;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace xCommons.Extensions
{
//
#region Requirements ...
///
/// an Internal Class for Registering Keyed Services ...
///
///
internal sealed class XKeyedService
where TService : class
{
public string Key { get; }
public TService Instance { get; }
public XKeyedService(
string key,
TService instance
)
{
//
if (key.IsNullOrEmpty() || instance.IsNull())
{
XException.InvalidArgs.Throw();
}
//
Key = key;
Instance = instance;
}
}
///
/// Holds the registration metadata for a keyed service.
///
internal sealed class XKeyedServiceRegistration
where TService : class
{
public string Key { get; private set; }
public bool OwnsInstance { get; private set; }
public ServiceLifetime Lifetime { get; private set; }
public Func Factory { get; private set; }
public XKeyedServiceRegistration(
string key,
Func factory,
ServiceLifetime lifetime,
bool ownsInstance
)
{
//
Key = key;
Factory = factory;
Lifetime = lifetime;
OwnsInstance = ownsInstance;
}
}
///
/// Reference equality comparer used to avoid disposing the same object twice.
/// Compatible with .NET Standard 2.0.
///
internal sealed class XReferenceEqualityComparer : IEqualityComparer