如何使用StructureMap将依赖项注入到WPF Window类中?

时间:2012-04-06 13:33:44

标签: c# wpf dependency-injection structuremap

我正在尝试使用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类中?

0 个答案:

没有答案