我遇到了一个有趣的错误。我已经升级了 Castle 和 NServiceBus。Castle 使用的是版本 3,现在使用的是版本 3.3.1。NServiceBus 使用的是 3.2.7,现在使用的是 4.6.1。
我的配置
/// <summary>
/// Castle Windsor Installer for NServiceBus
/// </summary>
public class NServiceBusInstaller : IWindsorInstaller {
public void Install(IWindsorContainer container, IConfigurationStore store) {
Configure.Serialization.Xml();
Configure.With()
.CastleWindsorBuilder(container)
.UseTransport<Msmq>()
.UnicastBus()
.SendOnly();
}
}
我收到的错误是这样的:
组件 NServiceBus.Scheduling.ScheduledTaskMessageHandler 具有生活方式绑定,但它没有指定强制的“scopeRootSelector”。
如果有人知道我必须改变什么,请告诉我。我已尝试查看所有配置选项,但不确定我缺少什么。这是在 Web ui 和服务托管在两个不同位置的服务的 Web 界面上。Web UI 只从用户那里获取信息并发送消息以进行处理,没有预期的返回值。这就是我将其设置为 SendOnly 配置的原因。
更新:这是 Sean Farmar 要求的信息。
private static IWindsorContainer _container;
private static void BootstrapContainer() {
_container = new WindsorContainer().Install(FromAssembly.This());
var controllerFactory = new WindsorControllerFactory(_container.Kernel);
ControllerBuilder.Current.SetControllerFactory(controllerFactory);
}
/// <summary>
/// IOC instructions to load Controllers via Castle.Windsor
/// </summary>
public class WindsorControllerFactory : DefaultControllerFactory {
private readonly IKernel _kernel;
public WindsorControllerFactory(IKernel kernel) {
_kernel = kernel;
}
public override void ReleaseController(IController controller) {
_kernel.ReleaseComponent(controller);
}
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType) {
if (controllerType == null) {
throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.",
requestContext.HttpContext.Request.Path));
}
return (IController)_kernel.Resolve(controllerType);
}
}
/// <summary>
/// Castle Windsor Installer for Controllers
/// </summary>
public class ControllersInstaller : IWindsorInstaller {
public void Install(IWindsorContainer container, IConfigurationStore store) {
container.Register(Classes.FromThisAssembly()
.BasedOn<IController>()
.LifestyleTransient());
}
}
/// <summary>
/// Facility to configure NHibernate
/// </summary>
public class PersistenceFacility : AbstractFacility {
protected override void Init() {
var config = BuildDatabaseConfiguration();
Kernel.Register(
Component.For<ISessionFactory>()
.UsingFactoryMethod(_ => config.BuildSessionFactory()),
Component.For<ISession>()
.UsingFactoryMethod(x => x.Resolve<ISessionFactory>().OpenSession())
);
}
private NHibernate.Cfg.Configuration BuildDatabaseConfiguration() {
return Fluently.Configure()
.Database(SetupDatabase())
.Mappings(x => x.FluentMappings.AddFromAssemblyOf<ClientServicesUploadsMap>())
.BuildConfiguration();
}
protected virtual IPersistenceConfigurer SetupDatabase() {
return MsSqlConfiguration.MsSql2005.ConnectionString(
c => c.FromConnectionStringWithKey("workflow"));
}
}
/// <summary>
/// Castle Windsor Facility Installer
/// </summary>
public class FacilityInstaller : IWindsorInstaller {
public void Install(IWindsorContainer container, IConfigurationStore store) {
container.AddFacility<PersistenceFacility>();
}
}
/// <summary>
/// Castle Windsor Installer for Repositories
/// </summary>
public class RepositoriesInstaller : IWindsorInstaller {
public void Install(IWindsorContainer container, IConfigurationStore store) {
container.Register(Classes.FromAssemblyContaining<ClientServicesUploadsRepository>() .Where(Component.IsInSameNamespaceAs<ClientServicesUploadsRepository>())
.WithService.DefaultInterfaces()
.LifestyleTransient()
);
}
}
/// <summary>
/// Castle Windsor Installer for NServiceBus
/// </summary>
public class NServiceBusInstaller : IWindsorInstaller {
public void Install(IWindsorContainer container, IConfigurationStore store) {
Configure.Serialization.Xml();
Configure.With()
.CastleWindsorBuilder(container)
.UseTransport<Msmq>()
.UnicastBus()
.SendOnly();
}
“/ClientServices”应用程序中的服务器错误。
组件 NServiceBus.Scheduling.ScheduledTaskMessageHandler 具有生活方式绑定,但它没有指定强制的“scopeRootSelector”。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:Castle.MicroKernel.ComponentRegistrationException:组件 NServiceBus.Scheduling.ScheduledTaskMessageHandler 已绑定生活方式,但未指定强制“scopeRootSelector”。
源错误:
第 191 行:Configure.Serialization.Xml(); 第 192 行:第 193 行:Configure.With() 第 194 行:.CastleWindsorBuilder(container) 第 195 行:.UseTransport()
源文件:C:\ClientServices\trunk\src\UI\Global.asax.cs 行:193
堆栈跟踪:
[ComponentRegistrationException:组件 NServiceBus.Scheduling.ScheduledTaskMessageHandler 已绑定生活方式,但未指定强制的“scopeRootSelector”。] Castle.MicroKernel.DefaultKernel.CreateScopeAccessorForBoundLifestyle(ComponentModel 模型)+212 Castle.MicroKernel.DefaultKernel.CreateLifestyleManager(ComponentModel 模型,IComponentActivator 激活器) +182 Castle.MicroKernel.Handlers.DefaultHandler.InitDependencies() +148 Castle.MicroKernel.Handlers.AbstractHandler.Init(IKernelInternal kernel) +171 Castle.MicroKernel.Handlers.DefaultHandlerFactory.Create(ComponentModel 模型) +71 Castle.MicroKernel.DefaultKernel .Castle.MicroKernel.IKernelInternal.CreateHandler(ComponentModel model) +133 Castle.MicroKernel.DefaultKernel.AddCustomComponent(ComponentModel model) +50 Castle.MicroKernel.Registration。组件注册1.Castle.MicroKernel.Registration.IRegistration.Register(IKernelInternal kernel) +267
Castle.MicroKernel.DefaultKernel.Register(IRegistration[] registrations) +178
Castle.Windsor.WindsorContainer.Register(IRegistration[] registrations) +59
NServiceBus.ObjectBuilder.CastleWindsor.WindsorObjectBuilder.NServiceBus.ObjectBuilder.Common.IContainer.Configure(Type concreteComponent, DependencyLifecycle dependencyLifecycle) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\ObjectBuilder.CastleWindsor\WindsorObjectBuilder.cs:89
NServiceBus.ObjectBuilder.Common.CommonObjectBuilder.ConfigureComponent(Type concreteComponent, DependencyLifecycle instanceLifecycle) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\ObjectBuilder\Common\CommonObjectBuilder.cs:54
NServiceBus.Unicast.Config.ConfigUnicastBus.ConfigureMessageHandlersIn(IEnumerable
1 种)在 y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Unicast\Config\ConfigUnicastBus.cs:164 NServiceBus.Unicast.Config.ConfigUnicastBus.LoadMessageHandlers(IEnumerable 1 orderedTypes) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Unicast\Config\ConfigUnicastBus.cs:147
NServiceBus.Unicast.Config.ConfigUnicastBus.LoadMessageHandlers() in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Unicast\Config\ConfigUnicastBus.cs:98
NServiceBus.EnsureLoadMessageHandlersWasCalled.Init() in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\ConfigureUnicastBus.cs:49
NServiceBus.Configure.<Initialize>b__10(INeedInitialization t) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Configure.cs:350
NServiceBus.<>c__DisplayClass23
1.b__20(Type t) in y:\ BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Configure.cs:555 System.Collections.Generic.List 1.ForEach(Action
1 action) +11010045 NServiceBus.Configure.ForAllTypes(Action1 action) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Configure.cs:379
NServiceBus.Configure.ActivateAndInvoke(Action
y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Configure.cs:549 NServiceBus.Configure.Initialize() in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus 中的 1 个操作,可为 Nullable`1 thresholdForWarning)。 Core\Configure.cs:350 NServiceBus.ConfigureExtensions.SendOnly(Configure config) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Config\ConfigureExtensions.cs:18 Lsr.ClientServices.UI.NServiceBusInstaller.Install(IWindsorContainer容器,IConfigurationStore 存储)在 C:\ClientServices\trunk\src\UI\Global.asax.cs:193 Castle.Windsor.Installer.AssemblyInstaller.Install(IWindsorContainer 容器,IConfigurationStore 存储)+229 Castle.Windsor.WindsorContainer.Install( IWindsorInstaller[] 安装程序,DefaultComponentInstaller 范围)+165 Castle.Windsor.WindsorContainer。安装(IWindsorInstaller[] 安装程序)+227 Lsr.ClientServices.UI.MvcApplication.BootstrapContainer() 在 C:\ClientServices\trunk\src\UI\Global.asax.cs:52 Lsr.ClientServices.UI.MvcApplication.Application_Start()在 C:\ClientServices\trunk\src\UI\Global.asax.cs:44