我在我的主項目中有FileHandler.ashx
文件。castle windsor - 沒有爲此對象定義的無參數構造函數
public class FileHandler : IHttpHandler
{
private readonly IAccountService _accountService;
private readonly IAttachmentService _attachmentService;
public FileHandler(IAccountService accountService, IAttachmentService attachmentService)
{
_accountService = accountService;
_attachmentService = attachmentService;
}
....
}
另外,我有HandlerInstaller
:
public class HandlersInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Classes.FromThisAssembly()
.Where(Component.IsInSameNamespaceAs<FileHandler>())
.WithService.DefaultInterfaces()
.LifestyleSingleton());
}
}
但是,當我嘗試調用文件FileHandler.ashx
我得到一個錯誤:
No parameterless constructor defined for this object.
的原因是什麼?如何解決它?
您的網頁是否有依賴項解析程序?不知道它如何與ashx協同工作,但在mvc/web.api中,您必須設置一個新的依賴關係解析器來支持具有參數的ctors; http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver –
你能提供更多的代碼/細節嗎?你如何將容器附加到你的項目?你有註冊FileHandler所依賴的服務嗎?你確定這是引入異常的類嗎? (我也不知道ashx是如何工作的) –
這樣做:http://bugsquash.blogspot.com/2009/11/windsor-managed-httpmodules.html但是用於HttpHandlers而不是HttpModules。 –