在版本 3.x 中排除特定的 nservicebus 主机处理程序 (类)

Exclude specific nservicebus host handlers (classes) in version 3.x

我有一个 NServiceBus 主机,它订阅了某个事件并有自己的处理程序 (#1)。该主机还引用了一个程序集,该程序集包含同一事件的另一个处理程序 (#2)。我想从 NServiceBus 配置中排除处理程序 #2,但我无法删除引用的程序集。

重要:

1) 我尝试使用此设置扫描:http://docs.particular.net/nservicebus/hosting/assembly-scanning

2) 我用的是NServiceBus版本3.x

删除程序集

NServiceBus v3 扫描程序集。如果在运行时不需要该程序集,则只需将其删除,这样就不会对其进行扫描。

仅仅因为它被引用并不意味着需要部署它。

不包括程序集(黑名单)

排除文档中提到的程序集:

var allAssemblies = AllAssemblies
    .Except("MyAssembly1.dll")
    .And("MyAssembly2.dll");
Configure.With(allAssemblies);

http://docs.particular.net/nservicebus/hosting/assembly-scanning#exclude-a-list-approach

包括程序集或类型(白名单)

只允许扫描一组特定的程序集或类型。基本上解析白名单范围内的程序集或类型。

程序集:

IEnumerable<Assembly> allowedAssembliesToScanForTypes;
Configure.With(allowedAssembliesToScanForTypes);
// or
Configure.With(assembly1, assembly2);

类型:

IEnumerable<Type> allowedTypesToScan;
Configure.With(allowedTypesToScan);

排除特定类型

// Results in the same assembly scanning as used by NServiceBus internally
var allTypes = from a in AllAssemblies.Except("Dummy") 
               from t in a.GetTypes()
               select t;

// Exclude handlers that you do not want to be registered
var allowedTypesToScan = allTypes
    .Where(t => t != typeof(EventMessageHandler)) 
    .ToList();

Configure.With(allowedTypesToScan);

http://docs.particular.net/nservicebus/hosting/assembly-scanning#include-a-list-approach-including-assemblies