C# WPF Caliburn IViewFactory未找到构造函数-';Castle.MicroKernel.Resolvers.DependencyResolvexException';

C# WPF Caliburn IViewFactory未找到构造函数-';Castle.MicroKernel.Resolvers.DependencyResolvexException';,c#,wpf,dependency-injection,castle-windsor,caliburn.micro,C#,Wpf,Dependency Injection,Castle Windsor,Caliburn.micro,我正在开发WPF应用程序(.NET 4.5),它使用MVVM和Caliburn通过IViewFactory接口引导视图。 我遇到了一个奇怪的问题,除了一个(QuestionRadioBtnViewModel)之外,我的ViewModels都被初始化了。 在运行时尝试初始化viewModel时 var questionRadBtnVm = _viewFactory.CreateQuestionRadioBtnViewModel(answer.Text); 返回错误消息: A first chan

我正在开发WPF应用程序(.NET 4.5),它使用MVVM和
Caliburn
通过
IViewFactory
接口引导视图。
我遇到了一个奇怪的问题,除了一个(
QuestionRadioBtnViewModel
)之外,我的ViewModels都被初始化了。
在运行时尝试初始化viewModel时

var questionRadBtnVm = _viewFactory.CreateQuestionRadioBtnViewModel(answer.Text);
返回错误消息:

A first chance exception of type 'Castle.MicroKernel.Resolvers.DependencyResolverException' occurred in Castle.Windsor.dll

Additional information: Could not resolve non-optional dependency for 'Corp.Conveyancing.Desktop.ViewModels.Question.QuestionRadioBtnViewModel' (Corp.Conveyancing.Desktop.ViewModels.Question.QuestionRadioBtnViewModel). Parameter 'stringValue' type 'System.String'
然而,方法签名和构造函数匹配得很好

IViewFactory:

 public interface IViewFactory
 {
     QuestionRadioBtnViewModel CreateQuestionRadioBtnViewModel(string textValue);
 }
问题RadioBTNViewModel

 public QuestionRadioBtnViewModel(IEventAggregator eventAggregator, string stringValue)
 {
    _stringValue = stringValue;
    _eventAggregator = eventAggregator;
 }
卡利本靴筒

public class ReactiveBootstrapper : BootstrapperBase
{
    public ReactiveBootstrapper()
    {
        Log.Info("Starting bootstrapper");
        Start();
    }

    protected override void OnStartup(object sender, StartupEventArgs e)
    {
        DisplayRootViewFor(typeof(MainViewModel));
    }

    protected override void BuildUp(object instance)
    {
        Container.BuildUp(instance);
    }

    protected override void Configure()
    {
        Container = new ApplicationContainer();

        Container.RegisterViewModels(typeof(MainViewModel));

        SetXamlLanguage();
        Container.Install(FromAssembly.Containing<IObjectModelFactory>());
        Container.AddFacility<LoggingFacility>(f => f.UseLog4Net(Assembly.GetEntryAssembly().GetName().Name + ".exe.log4net"));
        Container.AddFacility<TypedFactoryFacility>();
        Container.Register(Component.For<IViewFactory>().AsFactory());
        Container.Register(Component.For<IServerOperations>().ImplementedBy<ServerOperations>());
        Container.Register(Component.For<IQuestionControlFactory>().ImplementedBy<QuestionControlFactory>());
        Container.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero);

        RegisterWcfServices();

        Container.Register(Component.For<IQasManager>().ImplementedBy<QasWebManager>().DependsOn(Dependency.OnValue("url", Settings.Default.QasUrl)));
    }

    protected override IEnumerable<object> GetAllInstances(Type service)
    {
        return Container.ResolveAll(service).Cast<object>();
    }

    protected override IEnumerable<Assembly> SelectAssemblies()
    {
        return new[] {
            Assembly.GetExecutingAssembly(),
            typeof(MainViewModel).Assembly,
            typeof(MessageViewModel).Assembly
        };
    }

    protected override object GetInstance(Type service, string key)
    {
        if (string.IsNullOrWhiteSpace(key))
        {
            return Container.Resolve(service);
        }
        return Container.Resolve(key, service);
    }
}
public类ReactiveBootstrapper:BootstrapperBase
{
公共反应引导程序()
{
Log.Info(“启动引导程序”);
Start();
}
启动时受保护的覆盖无效(对象发送方、StartupEventArgs e)
{
DisplayRootViewFor(typeof(MainViewModel));
}
受保护的覆盖空洞堆积(对象实例)
{
容器。堆积(实例);
}
受保护的覆盖无效配置()
{
容器=新的ApplicationContainer();
RegisterViewModels(typeof(MainViewModel));
SetXamlLanguage();
Container.Install(fromsassembly.Containing());
Container.AddFacility(f=>f.UseLog4Net(Assembly.GetEntryAssembly().GetName().Name+“.exe.log4net”);
Container.AddFacility();
Container.Register(Component.For().AsFactory());
Container.Register(Component.For().ImplementedBy());
Container.Register(Component.For().ImplementedBy());
Container.AddFacility(f=>f.CloseTimeout=TimeSpan.Zero);
注册服务();
Register(Component.For().ImplementedBy().DependsOn(Dependency.OnValue(“url”,Settings.Default.QasUrl)));
}
受保护的重写IEnumerable GetAllInstances(类型服务)
{
返回Container.ResolveAll(service.Cast();
}
受保护的重写IEnumerable SelectAssemblys()
{
返回新的[]{
Assembly.getExecutionGassembly(),
类型(MainViewModel).Assembly,
类型(MessageViewModel).Assembly
};
}
受保护的覆盖对象GetInstance(类型服务,字符串键)
{
if(string.IsNullOrWhiteSpace(key))
{
返回容器。解析(服务);
}
返回容器。解析(密钥、服务);
}
}
使用
IViewFactory
的所有其他构造函数工作正常,数据传递没有问题。 我一定是遗漏了什么明显的东西?

是我自己发现的。
结果表明,不仅方法的签名必须匹配,而且传递的参数的名称也必须匹配

public QuestionRadioBtnViewModel(IEventAggregator eventAggregator, string stringValue)
stringValue
文本必须匹配

public interface IViewFactory
 {
     QuestionRadioBtnViewModel CreateQuestionRadioBtnViewModel(string stringValue);
 }