我正在开发一个多年未更新的应用程序,我应该更新它的依赖项。 Castle Windsor需要从2.5.4升级到3.3.0。升级后,以下内容不再编译:
container.Register(
Types.FromThisAssembly().Where(t => Attribute.IsDefined(t, typeof (ServiceBehaviorAttribute)))
.WithService.DefaultInterfaces()
.Configure(c => c.Interceptors(
InterceptorReference.ForType<ServiceInterceptor>(),
InterceptorReference.ForType<LoggingInterceptor>(),
InterceptorReference.ForType<ExceptionInterceptor>()).Anywhere.LifeStyle.Transient));
错误是:
Only assignment, call, increment, decrement, await expression, and new object expressions can be used as a statement.
ReSharper尝试通过分配变量来提供帮助:
container.Register(
Types.FromThisAssembly().Where(t => Attribute.IsDefined(t, typeof (ServiceBehaviorAttribute)))
.WithService.DefaultInterfaces()
.Configure(c =>
{
var componentRegistration = c.Interceptors(
InterceptorReference.ForType<ServiceInterceptor>(),
InterceptorReference.ForType<LoggingInterceptor>(),
InterceptorReference.ForType<ExceptionInterceptor>()).Anywhere.LifeStyle.Transient;
componentRegistration;
}));
然而,这会引发同样的错误。
我看起来很高和很低,正确地将拦截器同时设置为几种类型,但是我发现的所有示例都是旧的或只是为单个组件设置拦截器,例如来自文档的this one:
container.Register(
Component.For<ICalcService>()
.Interceptors(InterceptorReference.ForType<ReturnDefaultInterceptor>()).Last,
Component.For<ReturnDefaultInterceptor>()
);
这不起作用,因为我无法单独注册每个组件。
答案 0 :(得分:1)
将LifeStyle.Transient
替换为LifestyleTransient()