I’ve been trying to follow the advice in this answer
The problem is I get the error: No matching constructor found on type ‘FreecycleFrontEnd.MainWindow when the application starts up
Code below:
public partial class App : Application
{
private static readonly Logger log = LogManager.GetCurrentClassLogger();
private IKernel container;
protected override void OnStartup(StartupEventArgs e)
{
log.Debug("Application Starting Up");
IocKernel.Initialize(new IocConfiguration());
base.OnStartup(e);
}
}
public partial class MainWindow : Window
{
private IWebController _controller;
public MainWindow(IWebController controller)
{
this._controller = controller;
InitializeComponent();
Loaded += onLoaded;
}
public class IocConfiguration : NinjectModule
{
public override void Load()
{
Bind<IWebController>().To<WebController>().InSingletonScope();
Bind<UserControlViewModel>().ToSelf().InTransientScope(); // Create new instance every time
}
}
public static class IocKernel
{
private static StandardKernel _kernel;
public static T Get<T>()
{
return _kernel.Get<T>();
}
public static void Initialize(params INinjectModule[] modules)
{
if (_kernel == null)
{
_kernel = new StandardKernel(modules);
}
}
}
The code compiles, and executes up to base.OnStartup(e);
The Ninject configuration executes.
What have I missed?
Go to Source
Author: tonydev314