Make ServiceManager dispose services.

Scoped manager disposes only scoped services.
Added parameter to instruct manager to register all interfaces of a type.
This commit is contained in:
Alexandru Macocian
2021-10-02 07:07:35 +02:00
parent 30705c58cc
commit d6834e0215
9 changed files with 277 additions and 96 deletions
@@ -0,0 +1,12 @@
namespace Slim.Tests.Models
{
public sealed class IDisposableSingletonService : IIDisposableService
{
public bool DisposeCalled { get; set; }
public void Dispose()
{
this.DisposeCalled = true;
}
}
}
+1
View File
@@ -4,5 +4,6 @@ namespace Slim.Tests.Models
{
public interface IIDisposableService : IDisposable
{
bool DisposeCalled { get; set; }
}
}
+67 -4
View File
@@ -209,7 +209,7 @@ namespace Slim.Tests
public void MultiInterfaceDeclarationReturnsSameSingleton()
{
var di = new ServiceManager();
di.RegisterSingleton<MultiInterfaceService>();
di.RegisterSingleton<MultiInterfaceService>(registerAllInterfaces: true);
var singleton1 = di.GetService<IMultiInterfaceService1>();
var singleton2 = di.GetService<IMultiInterfaceService2>();
@@ -221,7 +221,7 @@ namespace Slim.Tests
public void MultiInterfaceDeclarationReturnsDifferentTransient()
{
var di = new ServiceManager();
di.RegisterTransient<MultiInterfaceService>();
di.RegisterTransient<MultiInterfaceService>(registerAllInterfaces: true);
var transient1 = di.GetService<IMultiInterfaceService1>();
var transient2 = di.GetService<IMultiInterfaceService2>();
@@ -233,7 +233,7 @@ namespace Slim.Tests
public void MultiInterfaceDeclarationWithFactoryReturnsSameSingleton()
{
var di = new ServiceManager();
di.RegisterSingleton(sp => new MultiInterfaceService());
di.RegisterSingleton(sp => new MultiInterfaceService(), registerAllInterfaces: true);
var singleton1 = di.GetService<IMultiInterfaceService1>();
var singleton2 = di.GetService<IMultiInterfaceService2>();
@@ -245,7 +245,7 @@ namespace Slim.Tests
public void MultiInterfaceDeclarationWithFactoryReturnsDifferentTransient()
{
var di = new ServiceManager();
di.RegisterTransient(sp => new MultiInterfaceService());
di.RegisterTransient(sp => new MultiInterfaceService(), registerAllInterfaces: true);
var transient1 = di.GetService<IMultiInterfaceService1>();
var transient2 = di.GetService<IMultiInterfaceService2>();
@@ -579,5 +579,68 @@ namespace Slim.Tests
di.GetServicesOfType<ISharedInterface>().Should().HaveCount(3);
di.GetServicesOfType(typeof(ISharedInterface)).Should().HaveCount(3).And.AllBeAssignableTo<ISharedInterface>();
}
[TestMethod]
public void DisposingServiceManagerShouldDisposeInstances()
{
var di = new ServiceManager();
di.RegisterSingleton<IIDisposableService, IDisposableService>();
var disposableService = di.GetService<IIDisposableService>();
di.Dispose();
disposableService.DisposeCalled.Should().BeTrue();
}
[TestMethod]
public void DisposingServiceManagerShouldDisposeAllServices()
{
var di = new ServiceManager();
di.RegisterScoped<IDisposableService>();
di.RegisterSingleton<IDisposableSingletonService>();
var disposableService = di.GetService<IDisposableService>();
var disposableSingletonService = di.GetService<IDisposableSingletonService>();
di.Dispose();
disposableSingletonService.DisposeCalled.Should().BeTrue();
disposableService.DisposeCalled.Should().BeTrue();
}
[TestMethod]
public void DisposingScopedServiceManagerShouldDisposeOnlyScopedServices()
{
var di = new ServiceManager();
di.RegisterScoped<IDisposableService>();
di.RegisterSingleton<IDisposableSingletonService>();
var disposableSingletonService = di.GetService<IDisposableSingletonService>();
var scopedDi = di.CreateScope();
var disposableService = scopedDi.GetService<IDisposableService>();
scopedDi.Dispose();
disposableSingletonService.DisposeCalled.Should().BeFalse();
disposableService.DisposeCalled.Should().BeTrue();
}
[TestMethod]
public void RegisterAllInterfacesFalseShouldRegisterOnlyTypeOfObject()
{
var di = new ServiceManager();
di.RegisterSingleton<MultiInterfaceService>();
di.GetService<MultiInterfaceService>().Should().NotBeNull();
var action = new Action(() =>
{
di.GetService<IMultiInterfaceService1>();
});
var action2 = new Action(() =>
{
di.GetService<IMultiInterfaceService2>();
});
action.Should().Throw<Exception>();
action2.Should().Throw<Exception>();
}
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ namespace Slim
/// <summary>
/// Register the current service manager as a valid dependency.
/// </summary>
/// <remarks>Same functionality as calling <see cref="IServiceProducer.RegisterSingleton(Type, Func{IServiceProvider, object})" /> with current <see cref="IServiceManager"/>.</remarks>
/// <remarks>Registers current service manager as <see cref="ServiceManager"/>, <see cref="IServiceManager"/>, <see cref="IServiceProducer"/>, <see cref="IServiceProvider"/>.</remarks>
void RegisterServiceManager();
/// <summary>
/// Builds all registered singletons.
+24 -12
View File
@@ -11,55 +11,61 @@ namespace Slim
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Singleton"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterSingleton<TClass>()
void RegisterSingleton<TClass>(bool registerAllInterfaces = false)
where TClass : class;
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Singleton"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="serviceFactory">Factory for the implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterSingleton<TClass>(Func<IServiceProvider, TClass> serviceFactory)
void RegisterSingleton<TClass>(Func<IServiceProvider, TClass> serviceFactory, bool registerAllInterfaces = false)
where TClass : class;
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterTransient<TClass>()
void RegisterTransient<TClass>(bool registerAllInterfaces = false)
where TClass : class;
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <param name="serviceFactory">Factory for the implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterTransient<TClass>(Func<IServiceProvider, TClass> serviceFactory)
void RegisterTransient<TClass>(Func<IServiceProvider, TClass> serviceFactory, bool registerAllInterfaces = false)
where TClass : class;
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Scoped"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterScoped<TClass>()
void RegisterScoped<TClass>(bool registerAllInterfaces = false)
where TClass : class;
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Scoped"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <param name="serviceFactory">Factory for the implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterScoped<TClass>(Func<IServiceProvider, TClass> serviceFactory)
void RegisterScoped<TClass>(Func<IServiceProvider, TClass> serviceFactory, bool registerAllInterfaces = false)
where TClass : class;
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
@@ -173,49 +179,55 @@ namespace Slim
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterTransient(Type tClass);
void RegisterTransient(Type tClass, bool registerAllInterfaces = false);
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <param name="serviceFactory">Factory for implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterTransient(Type tClass, Func<IServiceProvider, object> serviceFactory);
void RegisterTransient(Type tClass, Func<IServiceProvider, object> serviceFactory, bool registerAllInterfaces = false);
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Singleton"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterSingleton(Type tClass);
void RegisterSingleton(Type tClass, bool registerAllInterfaces = false);
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Singleton"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <param name="serviceFactory">Factory for implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterSingleton(Type tClass, Func<IServiceProvider, object> serviceFactory);
void RegisterSingleton(Type tClass, Func<IServiceProvider, object> serviceFactory, bool registerAllInterfaces = false);
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Scoped"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterScoped(Type tClass);
void RegisterScoped(Type tClass, bool registerAllInterfaces = false);
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Scoped"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <param name="serviceFactory">Factory for implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
void RegisterScoped(Type tClass, Func<IServiceProvider, object> serviceFactory);
void RegisterScoped(Type tClass, Func<IServiceProvider, object> serviceFactory, bool registerAllInterfaces = false);
}
}
+3 -2
View File
@@ -1,11 +1,12 @@
using Slim.Exceptions;
using System;
using Slim.Exceptions;
namespace Slim
{
/// <summary>
/// Interface allowing to request services from the <see cref="ServiceManager"/>.
/// </summary>
public interface IServiceProvider : System.IServiceProvider
public interface IServiceProvider : System.IServiceProvider, IDisposable
{
/// <summary>
/// Creates a scoped <see cref="IServiceProvider"/>.
+94 -31
View File
@@ -12,6 +12,9 @@ namespace Slim
/// </summary>
public sealed class ServiceManager : IServiceManager
{
private bool disposedValue;
private readonly bool scoped = false;
private Dictionary<Type, (Type, Lifetime)> InterfaceMapping { get; } = new Dictionary<Type, (Type, Lifetime)>();
private Dictionary<Type, object> Instances { get; } = new Dictionary<Type, object>();
private Dictionary<Type, Delegate> Factories { get; } = new Dictionary<Type, Delegate>();
@@ -37,6 +40,7 @@ namespace Slim
this.Factories = factories;
this.ExceptionHandlers = exceptionHandlers;
this.Resolvers = resolvers;
this.scoped = true;
}
/// <summary>
@@ -217,157 +221,172 @@ namespace Slim
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Singleton"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterSingleton<TClass>() where TClass : class
public void RegisterSingleton<TClass>(bool registerAllInterfaces = false) where TClass : class
{
this.RegisterService(typeof(TClass), Lifetime.Singleton);
this.RegisterService(typeof(TClass), Lifetime.Singleton, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Singleton"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <param name="serviceFactory">Factory for the implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterSingleton<TClass>(Func<IServiceProvider, TClass> serviceFactory) where TClass : class
public void RegisterSingleton<TClass>(Func<IServiceProvider, TClass> serviceFactory, bool registerAllInterfaces = false) where TClass : class
{
if (serviceFactory is null)
{
throw new ArgumentNullException(nameof(serviceFactory));
}
this.RegisterService(typeof(TClass), Lifetime.Singleton, null, serviceFactory);
this.RegisterService(typeof(TClass), Lifetime.Singleton, null, serviceFactory, registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterTransient<TClass>() where TClass : class
public void RegisterTransient<TClass>(bool registerAllInterfaces = false) where TClass : class
{
this.RegisterService(typeof(TClass), Lifetime.Transient);
this.RegisterService(typeof(TClass), Lifetime.Transient, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <param name="serviceFactory">Factory for the implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterTransient<TClass>(Func<IServiceProvider, TClass> serviceFactory) where TClass : class
public void RegisterTransient<TClass>(Func<IServiceProvider, TClass> serviceFactory, bool registerAllInterfaces = false) where TClass : class
{
if (serviceFactory is null)
{
throw new ArgumentNullException(nameof(serviceFactory));
}
this.RegisterService(typeof(TClass), Lifetime.Transient, null, serviceFactory);
this.RegisterService(typeof(TClass), Lifetime.Transient, null, serviceFactory, registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Scoped"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterScoped<TClass>() where TClass : class
public void RegisterScoped<TClass>(bool registerAllInterfaces = false) where TClass : class
{
this.RegisterService(typeof(TClass), Lifetime.Scoped);
this.RegisterService(typeof(TClass), Lifetime.Scoped, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Scoped"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <typeparam name="TClass">Type of implementation.</typeparam>
/// <param name="serviceFactory">Factory for the implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterScoped<TClass>(Func<IServiceProvider, TClass> serviceFactory) where TClass : class
public void RegisterScoped<TClass>(Func<IServiceProvider, TClass> serviceFactory, bool registerAllInterfaces = false) where TClass : class
{
if (serviceFactory is null)
{
throw new ArgumentNullException(nameof(serviceFactory));
}
this.RegisterService(typeof(TClass), Lifetime.Scoped, null, serviceFactory);
this.RegisterService(typeof(TClass), Lifetime.Scoped, null, serviceFactory, registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterTransient(Type tClass)
public void RegisterTransient(Type tClass, bool registerAllInterfaces = false)
{
this.RegisterService(tClass, Lifetime.Transient);
this.RegisterService(tClass, Lifetime.Transient, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Transient"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <param name="serviceFactory">Factory for implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterTransient(Type tClass, Func<IServiceProvider, object> serviceFactory)
public void RegisterTransient(Type tClass, Func<IServiceProvider, object> serviceFactory, bool registerAllInterfaces = false)
{
this.RegisterService(tClass, Lifetime.Transient, null, serviceFactory);
this.RegisterService(tClass, Lifetime.Transient, null, serviceFactory, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Singleton"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterSingleton(Type tClass)
public void RegisterSingleton(Type tClass, bool registerAllInterfaces = false)
{
this.RegisterService(tClass, Lifetime.Singleton);
this.RegisterService(tClass, Lifetime.Singleton, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Singleton"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <param name="serviceFactory">Factory for implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterSingleton(Type tClass, Func<IServiceProvider, object> serviceFactory)
public void RegisterSingleton(Type tClass, Func<IServiceProvider, object> serviceFactory, bool registerAllInterfaces = false)
{
this.RegisterService(tClass, Lifetime.Singleton, null, serviceFactory);
this.RegisterService(tClass, Lifetime.Singleton, null, serviceFactory, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Scoped"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterScoped(Type tClass)
public void RegisterScoped(Type tClass, bool registerAllInterfaces = false)
{
this.RegisterService(tClass, Lifetime.Scoped);
this.RegisterService(tClass, Lifetime.Scoped, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register a service into <see cref="ServiceManager"/> with <see cref="Lifetime.Scoped"/>.
/// Registers the service for all interfaces it implements.
/// </summary>
/// <param name="registerAllInterfaces">If true, <see cref="ServiceManager"/> will register all interfaces implemented by the provided class./></param>
/// <param name="tClass">Type of implementation.</param>
/// <param name="serviceFactory">Factory for implementation.</param>
/// <exception cref="ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when <see cref="ServiceManager"/> contains an entry for the provided interface type.</exception>
public void RegisterScoped(Type tClass, Func<IServiceProvider, object> serviceFactory)
public void RegisterScoped(Type tClass, Func<IServiceProvider, object> serviceFactory, bool registerAllInterfaces = false)
{
this.RegisterService(tClass, Lifetime.Scoped, null, serviceFactory);
this.RegisterService(tClass, Lifetime.Scoped, null, serviceFactory, registerAllInterfaces: registerAllInterfaces);
}
/// <summary>
/// Register the current service manager as a valid dependency.
/// </summary>
/// <remarks>Same functionality as calling <see cref="IServiceProducer.RegisterSingleton(Type, Func{IServiceProvider, object})" /> with current <see cref="IServiceManager"/>.</remarks>
/// <remarks>Registers current service manager as <see cref="ServiceManager"/>, <see cref="IServiceManager"/>, <see cref="IServiceProducer"/>, <see cref="IServiceProvider"/>.</remarks>
public void RegisterServiceManager()
{
this.RegisterService(typeof(ServiceManager), Lifetime.Singleton, null, new Func<IServiceProvider, object>((sp) => { return this; }));
this.RegisterSingleton<IServiceManager, ServiceManager>(sp => this);
this.RegisterSingleton<ServiceManager, ServiceManager>(sp => this);
this.RegisterSingleton<IServiceProducer, ServiceManager>(sp => this);
this.RegisterSingleton<IServiceProvider, ServiceManager>(sp => this);
}
/// <summary>
@@ -464,6 +483,14 @@ namespace Slim
{
this.Resolvers.Add(dependencyResolver);
}
/// <summary>
/// Cleans up resources and disposes of all disposable singletons.
/// </summary>
public void Dispose()
{
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
private IEnumerable<object> EnumerateAndReturnServicesOfType(Type type)
{
@@ -476,7 +503,7 @@ namespace Slim
}
}
}
private void RegisterService(Type tClass, Lifetime lifetime, Type tInterface = null, Delegate serviceFactory = null)
private void RegisterService(Type tClass, Lifetime lifetime, Type tInterface = null, Delegate serviceFactory = null, bool registerAllInterfaces = false)
{
if (tInterface is not null)
{
@@ -489,12 +516,15 @@ namespace Slim
return;
}
foreach (var i in tClass.GetInterfaces())
if (registerAllInterfaces)
{
this.Map(i, tClass, lifetime);
if (serviceFactory is not null)
foreach (var i in tClass.GetInterfaces())
{
this.RegisterFactory(i, serviceFactory);
this.Map(i, tClass, lifetime);
if (serviceFactory is not null)
{
this.RegisterFactory(i, serviceFactory);
}
}
}
@@ -733,5 +763,38 @@ namespace Slim
throw exception;
}
}
private void Dispose(bool disposing)
{
if (!this.disposedValue)
{
if (disposing)
{
/*
* Dispose of all instances. If this instance of ServiceManager is scoped, ignore the Singleton instances as they are shared
* across multiple service managers.
*/
foreach (var interfacePair in this.InterfaceMapping
.Where(kvp => kvp.Value.Item2 != Lifetime.Transient)
.Where(kvp => this.scoped is false || kvp.Value.Item2 != Lifetime.Singleton))
{
if (this.Instances.TryGetValue(interfacePair.Key, out var instance) && instance is IDisposable disposable)
{
disposable.Dispose();
}
else if (this.Instances.TryGetValue(interfacePair.Value.Item1, out var instance2) && instance2 is IDisposable disposable2)
{
disposable2.Dispose();
}
}
}
this.InterfaceMapping.Clear();
this.Instances.Clear();
this.Resolvers.Clear();
this.ExceptionHandlers.Clear();
this.Factories.Clear();
this.disposedValue = true;
}
}
}
}
+3 -3
View File
@@ -8,10 +8,10 @@
<Company />
<Product></Product>
<Description>Service lifetime management and dependency injection framework.</Description>
<AssemblyVersion>1.5.2</AssemblyVersion>
<FileVersion>1.5.2</FileVersion>
<AssemblyVersion>1.5.3</AssemblyVersion>
<FileVersion>1.5.3</FileVersion>
<PackageProjectUrl>https://github.com/AlexMacocian/Slim</PackageProjectUrl>
<Version>1.5.2</Version>
<Version>1.5.3</Version>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
+72 -43
View File
@@ -55,7 +55,7 @@
<summary>
Register the current service manager as a valid dependency.
</summary>
<remarks>Same functionality as calling <see cref="M:Slim.IServiceProducer.RegisterSingleton(System.Type,System.Func{Slim.IServiceProvider,System.Object})" /> with current <see cref="T:Slim.IServiceManager"/>.</remarks>
<remarks>Registers current service manager as <see cref="T:Slim.ServiceManager"/>, <see cref="T:Slim.IServiceManager"/>, <see cref="T:Slim.IServiceProducer"/>, <see cref="T:Slim.IServiceProvider"/>.</remarks>
</member>
<member name="M:Slim.IServiceManager.BuildSingletons">
<summary>
@@ -90,55 +90,61 @@
Interface allowing to produce services for the <see cref="T:Slim.ServiceManager"/>.
</summary>
</member>
<member name="M:Slim.IServiceProducer.RegisterSingleton``1">
<member name="M:Slim.IServiceProducer.RegisterSingleton``1(System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterSingleton``1(System.Func{Slim.IServiceProvider,``0},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Registers the service for all interfaces it implements.
</summary>
<typeparam name="TClass">Type of implementation.</typeparam>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="serviceFactory">Factory for the implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterSingleton``1(System.Func{Slim.IServiceProvider,``0})">
<member name="M:Slim.IServiceProducer.RegisterTransient``1(System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterTransient``1(System.Func{Slim.IServiceProvider,``0},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<param name="serviceFactory">Factory for the implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterTransient``1">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<typeparam name="TClass">Type of implementation.</typeparam>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterTransient``1(System.Func{Slim.IServiceProvider,``0})">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<typeparam name="TClass">Type of implementation.</typeparam>
<param name="serviceFactory">Factory for the implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterScoped``1">
<member name="M:Slim.IServiceProducer.RegisterScoped``1(System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Scoped"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterScoped``1(System.Func{Slim.IServiceProvider,``0})">
<member name="M:Slim.IServiceProducer.RegisterScoped``1(System.Func{Slim.IServiceProvider,``0},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Scoped"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<param name="serviceFactory">Factory for the implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
@@ -252,55 +258,61 @@
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterTransient(System.Type)">
<member name="M:Slim.IServiceProducer.RegisterTransient(System.Type,System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterTransient(System.Type,System.Func{Slim.IServiceProvider,System.Object})">
<member name="M:Slim.IServiceProducer.RegisterTransient(System.Type,System.Func{Slim.IServiceProvider,System.Object},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<param name="serviceFactory">Factory for implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterSingleton(System.Type)">
<member name="M:Slim.IServiceProducer.RegisterSingleton(System.Type,System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterSingleton(System.Type,System.Func{Slim.IServiceProvider,System.Object})">
<member name="M:Slim.IServiceProducer.RegisterSingleton(System.Type,System.Func{Slim.IServiceProvider,System.Object},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<param name="serviceFactory">Factory for implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterScoped(System.Type)">
<member name="M:Slim.IServiceProducer.RegisterScoped(System.Type,System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Scoped"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.IServiceProducer.RegisterScoped(System.Type,System.Func{Slim.IServiceProvider,System.Object})">
<member name="M:Slim.IServiceProducer.RegisterScoped(System.Type,System.Func{Slim.IServiceProvider,System.Object},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Scoped"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<param name="serviceFactory">Factory for implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
@@ -463,109 +475,121 @@
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterSingleton``1">
<member name="M:Slim.ServiceManager.RegisterSingleton``1(System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterSingleton``1(System.Func{Slim.IServiceProvider,``0})">
<member name="M:Slim.ServiceManager.RegisterSingleton``1(System.Func{Slim.IServiceProvider,``0},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<param name="serviceFactory">Factory for the implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterTransient``1">
<member name="M:Slim.ServiceManager.RegisterTransient``1(System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterTransient``1(System.Func{Slim.IServiceProvider,``0})">
<member name="M:Slim.ServiceManager.RegisterTransient``1(System.Func{Slim.IServiceProvider,``0},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<param name="serviceFactory">Factory for the implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterScoped``1">
<member name="M:Slim.ServiceManager.RegisterScoped``1(System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Scoped"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterScoped``1(System.Func{Slim.IServiceProvider,``0})">
<member name="M:Slim.ServiceManager.RegisterScoped``1(System.Func{Slim.IServiceProvider,``0},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Scoped"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<typeparam name="TClass">Type of implementation.</typeparam>
<param name="serviceFactory">Factory for the implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterTransient(System.Type)">
<member name="M:Slim.ServiceManager.RegisterTransient(System.Type,System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterTransient(System.Type,System.Func{Slim.IServiceProvider,System.Object})">
<member name="M:Slim.ServiceManager.RegisterTransient(System.Type,System.Func{Slim.IServiceProvider,System.Object},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Transient"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<param name="serviceFactory">Factory for implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterSingleton(System.Type)">
<member name="M:Slim.ServiceManager.RegisterSingleton(System.Type,System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterSingleton(System.Type,System.Func{Slim.IServiceProvider,System.Object})">
<member name="M:Slim.ServiceManager.RegisterSingleton(System.Type,System.Func{Slim.IServiceProvider,System.Object},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Singleton"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<param name="serviceFactory">Factory for implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterScoped(System.Type)">
<member name="M:Slim.ServiceManager.RegisterScoped(System.Type,System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Scoped"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<exception cref="T:System.InvalidOperationException">Thrown when <see cref="T:Slim.ServiceManager"/> contains an entry for the provided interface type.</exception>
</member>
<member name="M:Slim.ServiceManager.RegisterScoped(System.Type,System.Func{Slim.IServiceProvider,System.Object})">
<member name="M:Slim.ServiceManager.RegisterScoped(System.Type,System.Func{Slim.IServiceProvider,System.Object},System.Boolean)">
<summary>
Register a service into <see cref="T:Slim.ServiceManager"/> with <see cref="F:Slim.Lifetime.Scoped"/>.
Registers the service for all interfaces it implements.
</summary>
<param name="registerAllInterfaces">If true, <see cref="T:Slim.ServiceManager"/> will register all interfaces implemented by the provided class./></param>
<param name="tClass">Type of implementation.</param>
<param name="serviceFactory">Factory for implementation.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the provided serviceFactory is null.</exception>
@@ -575,7 +599,7 @@
<summary>
Register the current service manager as a valid dependency.
</summary>
<remarks>Same functionality as calling <see cref="M:Slim.IServiceProducer.RegisterSingleton(System.Type,System.Func{Slim.IServiceProvider,System.Object})" /> with current <see cref="T:Slim.IServiceManager"/>.</remarks>
<remarks>Registers current service manager as <see cref="T:Slim.ServiceManager"/>, <see cref="T:Slim.IServiceManager"/>, <see cref="T:Slim.IServiceProducer"/>, <see cref="T:Slim.IServiceProvider"/>.</remarks>
</member>
<member name="M:Slim.ServiceManager.CreateScope">
<summary>
@@ -642,5 +666,10 @@
</remarks>
<param name="dependencyResolver"><see cref="T:Slim.Resolvers.IDependencyResolver"/> that manually creates a dependency.</param>
</member>
<member name="M:Slim.ServiceManager.Dispose">
<summary>
Cleans up resources and disposes of all disposable singletons.
</summary>
</member>
</members>
</doc>