NServiceBus - 扫描所有组件
NServiceBus.dll - 版本5.2.9 & NServiceBus.Host - 版本6.0.0NServiceBus - 扫描所有组件
我开发可插拔的加载项工作流应用程序。
在我的解决方案中,我有一个使用NServiceBus.Host.exe托管的NServiceBus主机程序集。为了防止扫描,我在NServiceBus.Host.exe.config中定义了EndpointConfigurationType。
<appSettings>
<add key="EndpointConfigurationType" value="Libra.Workflow.Host.EndpointConfig, Libra.Workflow.Host" />
</appSettings>
我已经验证了这一配置被使用,因为如果我把一些未知的类型我得到一个错误,也因为我EndpointConfig类被实例化任何扫描发生之前。
在这个类中我已经加入
public void Customize(BusConfiguration cfg)
{
cfg.AssembliesToScan(AllAssemblies.Matching("Libra.Workflow.Messages.dll"));
...
}
现在的自定义方法,当我运行这个项目,我得到一个错误,因为NServiceBus是扫描所有组件和做System.AddIn的性质有些组件不能扫描!
此扫描发生在Libra.Workflow.Host实例化之后,但在定制方法调用之前已经实例化了。下面是该扫描调用堆栈:
at NServiceBus.Hosting.Helpers.AssemblyScanner.ScanAssembly(String assemblyPath, AssemblyScannerResults results) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Hosting\Helpers\AssemblyScanner.cs:line 153
at NServiceBus.Hosting.Helpers.AssemblyScanner.GetScannableAssemblies() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Hosting\Helpers\AssemblyScanner.cs:line 63
at NServiceBus.GenericHost..ctor(IConfigureThisEndpoint specifier, String[] args, List`1 defaultProfiles, String endpointName, IEnumerable`1 scannableAssembliesFullName) in c:\BuildAgent\work\a3de8759ee491634\src\NServiceBus.Hosting.Windows\GenericHost.cs:line 33
at NServiceBus.Hosting.Windows.WindowsHost..ctor(Type endpointType, String[] args, String endpointName, IEnumerable`1 scannableAssembliesFullName) in c:\BuildAgent\work\a3de8759ee491634\src\NServiceBus.Hosting.Windows\WindowsHost.cs:line 21
at NServiceBus.Hosting.Windows.HostServiceLocator.DoGetInstance(Type serviceType, String key) in c:\BuildAgent\work\a3de8759ee491634\src\NServiceBus.Hosting.Windows\HostServiceLocator.cs:line 31
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 49
该错误消息我得到的是:
Could not enumerate all types for
'C:\msc\Trunk\Libra.Workflow\Build\Libra.Workflow.Host\AddIns\Libra.Workflow\Libra.Workflow.Processors.dll'
为什么NServiceBus扫描这个DLL,我该如何预防呢?
注意:因为这是一个AddIn DLL,所以在Libra.Workflow.Host和其他相关的程序集中都没有引用它,所以NServiceBus绝对没有必要去触摸它。
由NServiceBus.Host完成的限制程序集扫描的一种方法是使用/ scannedAssemblies开关。一个需要注意的是明确地传送NServiceBus.Core和NServiceBus.Host组件:
NServiceBus.Host.exe /scannedAssemblies:"NServiceBus.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=9fc386479f8a226c" /scannedAssemblies:"NServiceBus.Host, Version=6.0.0.0, Culture=neutral, PublicKeyToken=9fc386479f8a226c"
此命令将扫描经由EndpointConfigurationType应用设置中指定的那些NServiceBus组件和组件。如果你想指定额外的组件(比如你的Libra.Workflow.Messages),你可以添加额外/扫描组件。
有关详细信息,请参阅此文档页面:http://docs.particular.net/nservicebus/hosting/nservicebus-host/#configuring-the-endpoint-controlling-assembly-scanning-using-the-command-line。
谢谢,正是我所需要的,这适用于.exe模式和NTService模式。 你知道是否有任何核心程序集,我必须添加像NServiceBus.Core? –
您还应该指定您正在使用的任何扩展组合件。例如,如果您使用除MSMQ以外的运输工具,则还应该添加运输组合。有关组件扫描的更多详细信息,请参阅此doco:http://docs.particular.net/nservicebus/hosting/assembly-scanning#controlling-the-assemblies-to-scan。 –
再次感谢您。正是我需要的。 –
您是否需要将Libra.Workflow.Processors.dll依赖项添加到程序集扫描中? –
加载项的事情是它们的一些依赖关系位于其他地方,更具体地说是在运行主机的子文件夹中。 当我构建一个加载项时,我引用一个AddInView,但是我设置了Copy Local = False,所以AddInView.dll不会在AddIn文件夹中结束。 的结构是这样的:。 '\加载项\ Libra.Workflow \ Libra.Workflow.Processors.dll' '\ AddInViews \ Libra.Workflow.Processors.Pipeline.AddInView.dll' 此第二DLL是扫描仪找不到的依赖。它不包含在AddIn中的原因是因为所有加载项共享相同的AddInView.dll –
但是我发现了一个临时解决方法,但非常想停止NServiceBus扫描。的解决方法是将额外的子文件夹添加到在.config文件组件探测 ''' '' '' assemblyBinding>'' ' 我 –