2

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

我拥有的代码示例是:

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>();

我需要做什么才能根据需要将依赖项注入到 Window 类中?

4

0 回答 0