By default all assemblies in the endpoint's
bin directory are scanned in search of related interfaces so that the endpoint can configure them automatically.
NServiceBus.) is automatically included since it is required for endpoints to properly function.
There are some cases where finer control over which assemblies are loaded is required:
- To limit the number of assemblies being scanned and hence provide improvements to startup time.
- If hosting multiple endpoints out of the same directory each endpoint may require a subset of assemblies to be loaded.
NServiceBus.are not considered a core assembly but will still need to be included when customizing the assembly scanning.
Assemblies in nested directories are scanned.
An "Include a list" approach is used. Since many extensions such as transports and persisters in external NuGet packages relied on assembly scanning, this proved to be problematic. If the list of generated assemblies does include extension assemblies, the endpoint would fail at runtime with some unexpected, hard to diagnose behaviors.
var excludesBuilder = AllAssemblies .Except("MyAssembly1.dll") .And("MyAssembly2.dll"); busConfiguration.AssembliesToScan(excludesBuilder);
var allTypes = from a in AllAssemblies.Except("Dummy") from t in a.GetTypes() select t; var allowedTypesToScan = allTypes .Where(t => t != typeof(GenericHandler)) .ToList(); busConfiguration.TypesToScan(allowedTypesToScan);
busConfiguration.AssembliesToScan(myListOfAssemblies); // or busConfiguration.AssembliesToScan(assembly1, assembly2);
var includesBuilder = AllAssemblies .Matching("NServiceBus") .And("MyCompany.") .And("SomethingElse"); busConfiguration.AssembliesToScan(includesBuilder);
AllAssemblies helper class can be used to create a list of assemblies either by creating a blacklist using the method
Except or a whitelist by using Matching or a combination of both.
Andmethods behave like
var excludesBuilder = AllAssemblies .Matching("NServiceBus") .And("MyCompany.") .Except("BadAssembly.dll"); busConfiguration.AssembliesToScan(excludesBuilder);