我有一个 MVC 应用程序,它在任何地方都使用 Windsor,并且在 Windsor Castle 的任何地方都可以正常工作,但现在我正在向其中添加新代码,但它无法正常工作。我使用以下代码配置了 Castle:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<IFileUploadService>().ImplementedBy<FileUploadService>().DependsOn(Parameter.ForKey("x").Eq(
"test")).LifeStyle.PerWebRequest);
}
FileUploadService 定义如下:
public class FileUploadService : IFileUploadService
{
public FileUploadService(string x)
{
// use x
}
}
我确定安装程序行正在调用(调试显示该行在应用程序启动时运行。
我有一个控制器,定义如下:
public FileUploadController(IConfiguration Configuration, IFileUploadService fileUploadService)
{
this.Configuration = Configuration;
this.fileUploadService = fileUploadService;
}
当我运行此应用程序时,我收到此错误:
Can't create component 'FileUploadService' as it has dependencies to be satisfied.
FileUploadService is waiting for the following dependencies:
Keys (components with specific keys)
- x which was not registered.
问题是什么?我有他们正在工作的类似代码。