Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用StructureMap将依赖项注入WPF窗口类?_C#_Wpf_Dependency Injection_Structuremap - Fatal编程技术网

C# 如何使用StructureMap将依赖项注入WPF窗口类?

C# 如何使用StructureMap将依赖项注入WPF窗口类?,c#,wpf,dependency-injection,structuremap,C#,Wpf,Dependency Injection,Structuremap,我正在尝试使用StructureMap将依赖项注入到我的WPF窗口构造函数中 我拥有的代码示例如下: public partial class PanelConfiguration : Window { private IPanelConfigurationService _panelConfiguration; public PanelConfiguration(IPanelConfigurationService panelConfiguration) {

我正在尝试使用StructureMap将依赖项注入到我的WPF窗口构造函数中

我拥有的代码示例如下:

public partial class PanelConfiguration : Window
{
    private IPanelConfigurationService _panelConfiguration; 

    public PanelConfiguration(IPanelConfigurationService panelConfiguration)
    {
        _panelConfiguration = panelConfiguration;
    }
}
我将ObjectFactory配置为

// I was hoping the following would inject the interface into the constructor for me
For<PanelConfiguration>()
    .Use<PanelConfiguration>()
    .Ctor<IPanelConfigurationService>().Is<PanelConfigurationService>();

For<IPanelConfigurationRepository>()
        .Use<PanelConfigurationRepository>()
        .Ctor<string>("qFile").Is(config.QDefault);

For<IPanelConfigurationService>()
    .Use<PanelConfigurationService>();
//我希望下面的代码能为我将接口注入到构造函数中
For()
.Use()
.Ctor().Is();
For()
.Use()
.Ctor(“qFile”).Is(config.QDefault);
For()
.使用();

我需要做什么才能根据需要将依赖项注入窗口类?

您是否尝试过从StructureMap解析PanelConfiguration窗口?您好@DavidNelson,我不确定您的意思?你能解释一下吗?谢谢。我的意思是从StructureMap获取PanelConfiguration的实例,就像获取任何其他配置类型的实例一样。我不熟悉StructureMap,但所有DI框架都有一些“context.Resolve();”的等价物。谢谢,原来我被一个PEBKAC错误弄糊涂了。我已经解决了:)你试过简单地从StructureMap解析PanelConfiguration窗口吗?嗨@DavidNelson,我不知道你的意思是什么?你能解释一下吗?谢谢。我的意思是从StructureMap获取PanelConfiguration的实例,就像获取任何其他配置类型的实例一样。我不熟悉StructureMap,但所有DI框架都有一些“context.Resolve();”的等价物。谢谢,原来我被一个PEBKAC错误弄糊涂了。我已经解决了:)