我有wpf应用程序和DI:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
IKernel kernel = new StandardKernel(new InjectModule());
MainWindow window = kernel.Get<MainWindow>();
window.Show();
base.OnStartup(e);
}
}
MainWindow 的内容:
[Inject]
public MainWindow(ISomeRepository1 someRepository1, ISomeRepository2 someRepository2, ISomeRepository3 someRepository3)
{
...
工作正常,继续。有一个连接按钮。单击时创建服务网关:
private void ConnectClick(object sender, RoutedEventArgs e)
{
if (Gateway == null)
{
Gateway = new Gateway(Path.Text);
....
所以问题所在:
private void DocumentsClick(object sender, RoutedEventArgs e)
{
_documentContainer = new DocumentContainer(Gateway, someRepository1, someRepository2, someRepository3);
_documentContainer.Show();
}
我创建new DocumentContainer(Gateway, someRepository1, someRepository2, someRepository3);
但我需要注入它并且DocumentContainer在MainWindow
construstor中创建。并在DocumentsClick
上展示它。
请,任何帮助。