我的主项目中有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时出现错误:


  没有为此对象定义无参数构造函数。


是什么原因?如何解决?

最佳答案

我认为您必须提供一个空的构造函数

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

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

      ....
    }

10-08 19:54