var assemblies = GetType().Assembly .GetReferencedAssemblies() .Select(n => Assembly.Load(n)) .ToList(); assemblies.Add(GetType().Assembly); NServiceBus.Configure.With(assemblies);
This restricts the assembly scanning process to only the assemblies that your endpoint explicitly references. We can extract this code to an extension method so we can use it in other endpoints:
public static IEnumerable<Assembly> ReferencedAssemblies(this Type type) { var assemblies = type.Assembly .GetReferencedAssemblies() .Select(n => Assembly.Load(n)) .ToList(); assemblies.Add(GetType().Assembly); return assemblies; }
Now our endpoint initialization looks like this:
NServiceBus.Configure.With(GetType() .ReferencedAssemblies());