ContainerGetTypesToRegister Method (Type, IEnumerableAssembly)

Simple Injector
Returns all concrete non-generic types that are located in the supplied assemblies and implement or inherit from the supplied serviceType. serviceType can be an open-generic type.

Namespace:  SimpleInjector
Assembly:  SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
Syntax

public IEnumerable<Type> GetTypesToRegister(
	Type serviceType,
	IEnumerable<Assembly> assemblies
)

Parameters

serviceType
Type: SystemType
The base type or interface to find derived types for. This can be both a non-generic and open-generic type.
assemblies
Type: System.Collections.GenericIEnumerableAssembly
A list of assemblies that will be searched.

Return Value

Type: IEnumerableType
A collection of types.
Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when one of the arguments contain a null reference.
Remarks

Use this method when you need influence the types that are registered using Register or Collections.Register. The Register overloads that take a collection of Assembly objects use this method internally to get the list of types that need to be registered. Instead of calling such overload, you can call an overload that takes a list of Type objects and pass in a filtered result from this GetTypesToRegister method.
C#
var container = new Container();

var assemblies = new[] { typeof(ICommandHandler<>).Assembly };
var types = container.GetTypesToRegister(typeof(ICommandHandler<>), assemblies)
    .Where(type => type.IsPublic);

container.Register(typeof(ICommandHandler<>), types);
This example calls the GetTypesToRegister method to request a list of concrete implementations of the ICommandHandler<T> interface from the assembly of that interface. After that all internal types are filtered out. This list is supplied to the Register(Type, IEnumerable<Type>) overload to finish the registration.
See Also

Reference