gpt4 book ai didi

c# - caSTLe windsor - 没有为此对象定义无参数构造函数

转载 作者:太空宇宙 更新时间:2023-11-03 16:00:44 27 4
gpt4 key购买 nike

我的主项目中有 FileHandler.ashx 文件。

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.

这是什么原因?如何解决?

最佳答案

我认为你必须提供一个像那样的空构造器

public class FileHandler : IHttpHandler
{
private readonly IAccountService _accountService;
private readonly IAttachmentService _attachmentService;

public FileHandler()
{
}
public FileHandler(IAccountService accountService, IAttachmentService attachmentService)
{
_accountService = accountService;
_attachmentService = attachmentService;
}

....
}

关于c# - caSTLe windsor - 没有为此对象定义无参数构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21589213/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com