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.RavenDB.dllare not considered a core assembly but still must be included when customizing the assembly scanning.
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.
Assemblies in nested directories are scanned.
Further control of scanned assemblies can be configured using an "include list" approach.
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 by creating: a) a deny list using the method
Except, b) an allow list by using
Matching, or c) a combination of both.
Andmethods behave like
var excludesBuilder = AllAssemblies .Matching("NServiceBus") .And("MyCompany.") .Except("BadAssembly.dll"); busConfiguration.AssembliesToScan(excludesBuilder);
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 != badType) .ToList(); busConfiguration.TypesToScan(allowedTypesToScan);