CollectionRegistratorExtensions
Represents the extension methods of IDependencyCollectionRegistrator.
using Stashbox.Exceptions;
using Stashbox.Registration.Fluent;
using Stashbox.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Stashbox
{
public static class CollectionRegistratorExtensions
{
public static IStashboxContainer RegisterTypesAs<TFrom>(this IDependencyCollectionRegistrator registrator, IEnumerable<Type> types, Func<Type, bool> selector = null, Action<RegistrationConfigurator> configurator = null) where TFrom : class
{
return registrator.RegisterTypesAs(typeof(TFrom), types, selector, configurator);
}
public static IStashboxContainer RegisterTypesAs<TFrom>(this IDependencyCollectionRegistrator registrator, Assembly assembly, Func<Type, bool> selector = null, Action<RegistrationConfigurator> configurator = null) where TFrom : class
{
return registrator.RegisterTypesAs(typeof(TFrom), assembly.CollectTypes(), selector, configurator);
}
public static IStashboxContainer RegisterTypesAs(this IDependencyCollectionRegistrator registrator, Type typeFrom, Assembly assembly, Func<Type, bool> selector = null, Action<RegistrationConfigurator> configurator = null)
{
return registrator.RegisterTypesAs(typeFrom, assembly.CollectTypes(), selector, configurator);
}
public static IStashboxContainer RegisterAssembly(this IDependencyCollectionRegistrator registrator, Assembly assembly, Func<Type, bool> selector = null, Func<Type, Type, bool> serviceTypeSelector = null, bool registerSelf = true, Action<RegistrationConfigurator> configurator = null)
{
return registrator.RegisterTypes(assembly.CollectTypes(), selector, serviceTypeSelector, registerSelf, configurator);
}
public static IStashboxContainer RegisterAssemblies(this IDependencyCollectionRegistrator registrator, IEnumerable<Assembly> assemblies, Func<Type, bool> selector = null, Func<Type, Type, bool> serviceTypeSelector = null, bool registerSelf = true, Action<RegistrationConfigurator> configurator = null)
{
Shield.EnsureNotNull(assemblies, "assemblies");
foreach (Assembly assembly in assemblies) {
registrator.RegisterAssembly(assembly, selector, serviceTypeSelector, registerSelf, configurator);
}
return (IStashboxContainer)registrator;
}
public static IStashboxContainer RegisterAssemblyContaining<TFrom>(this IDependencyCollectionRegistrator registrator, Func<Type, bool> selector = null, Func<Type, Type, bool> serviceTypeSelector = null, bool registerSelf = true, Action<RegistrationConfigurator> configurator = null) where TFrom : class
{
return registrator.RegisterAssemblyContaining(typeof(TFrom), selector, serviceTypeSelector, registerSelf, configurator);
}
public static IStashboxContainer RegisterAssemblyContaining(this IDependencyCollectionRegistrator registrator, Type typeFrom, Func<Type, bool> selector = null, Func<Type, Type, bool> serviceTypeSelector = null, bool registerSelf = true, Action<RegistrationConfigurator> configurator = null)
{
return registrator.RegisterAssembly(typeFrom.GetTypeInfo().get_Assembly(), selector, serviceTypeSelector, registerSelf, configurator);
}
public static IStashboxContainer ComposeAssemblies(this IDependencyCollectionRegistrator registrator, IEnumerable<Assembly> assemblies, Func<Type, bool> selector = null)
{
Shield.EnsureNotNull(assemblies, "assemblies");
foreach (Assembly assembly in assemblies) {
registrator.ComposeAssembly(assembly, selector);
}
return (IStashboxContainer)registrator;
}
public static IStashboxContainer ComposeBy<TCompositionRoot>(this IDependencyCollectionRegistrator registrator, params object[] compositionRootArguments) where TCompositionRoot : class, ICompositionRoot
{
return registrator.ComposeBy(typeof(TCompositionRoot), compositionRootArguments);
}
public static IStashboxContainer ComposeAssembly(this IDependencyCollectionRegistrator registrator, Assembly assembly, Func<Type, bool> selector = null)
{
Shield.EnsureNotNull(assembly, "assembly");
IEnumerable<Type> enumerable = ((selector == null) ? assembly.CollectTypes() : assembly.CollectTypes().Where(selector)).Where(delegate(Type type) {
if (type.IsResolvableType())
return type.IsCompositionRoot();
return false;
});
if (!enumerable.Any())
throw new CompositionRootNotFoundException(assembly, null);
foreach (Type item in enumerable) {
registrator.ComposeBy(item);
}
return (IStashboxContainer)registrator;
}
}
}