这是模块:
public class InjectModule : NinjectModule
{
public override void Load()
{
Bind<DbContext>().ToSelf().InSingletonScope();
Bind<ISomeRepository>().To<SomeRepository>()
.InThreadScope();
Bind<MainWindow>().ToSelf().InThreadScope();
Bind<IKernel>() //how to bind???
}
}
我的应用程序:
protected override void OnStartup(StartupEventArgs e)
{
IKernel kernel = new StandardKernel(new InjectModule());
MainWindow window = kernel.Get<MainWindow>();
window.Show();
base.OnStartup(e);
}
我需要内核作为DependencyResolver
主窗口中的属性。如何使它工作?
public partial class MainWindow
{
[Inject]
public IKernel DependencyResolver { get; set; }
}