caSTLe-windsor - 替换 CaSTLe Windsor 中过时的 AllTypes 类

标签 castle-windsor

我有这个来自旧城堡的代码:

IoC.Container.Register( 
    AllTypes
        .FromAssemblyNamed(a)
        .Pick().WithService.FirstInterface()
        .Configure(o => o.LifeStyle.PerWebRequest));

当我升级到城堡 3.2 时,出现此错误:

Castle.MicroKernel.Registration.AllTypes' is obsolete



而这个错误是 o.LifeStyle.PerWebRequest :

Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement



我怎样才能解决这个问题?

最佳答案

就像@charleh 说的,AllTypes被替换为 Classes所以解决这个问题是一个简单的查找和替换。
实际上,如果您查看编译器警告,它应该说:

'AllTypes' has been deprecated and will be removed in future releases. Use 'Classes' static class (if you want to just register concrete classes) or 'Types' static class (if you want to register interfaces or abstract classes too) instead. It exposes exactly the same methods.


这种变化的原因是AllTypes是谎言 - 它只匹配具体(非抽象)类,所以 Classes是一个更好的名字,可以更好地告诉你它的真正作用。
至于另一个问题,将属性调用更改为方法调用将解决它:
Container.Register(
    Classes.FromAssemblyNamed(a)
        .Pick().WithServiceFirstInterface()
        .Configure( o => o.LifestylePerWebRequest()));
或者更简单,跳过 Configure :
Container.Register(
    Classes.FromAssemblyNamed(a)
        .Pick().WithServiceFirstInterface()
        .LifestylePerWebRequest());
温莎发货 BreakingChanges.txt描述重大更改和如何升级的文件。

关于caSTLe-windsor - 替换 CaSTLe Windsor 中过时的 AllTypes 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16231955/

相关文章:

c# - Caliburn.Micro - 使用 CaSTLe.Windsor 从 IoC 容器解析 ViewModel

c# - CaSTLe Windsor Ms Adapter Core 2.0 实现

asp.net-mvc - 如何让温莎城堡自动注册没有任何依赖关系的 Controller ?

c# - CaSTLe Windsor "Container"和 "Kernel"有什么区别?

.net - 适合初学者的 IOC 框架 (.net)?

c# - "Common Language Runtime detected an invalid program"位于带有 CaSTLe Windsor 的 Azure Web 角色上

c# - 使用 'where' 谓词从 Windsor CaSTLe 中的 Assembly 注册类型

inversion-of-control - 自定义配置注入(inject) - CaSTLe Windsor/IoC 的新手

caSTLe-windsor - 使用 xml/app.config 配置 CaSTLe Windsor

f# - CaSTLe Windsor - DependsOn 在 F# 中不起作用?