protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // Init Ninject var ninjectBootstrapper = new Ninject.NinjectBootstrapper(); ninjectBootstrapper.LoadModules(); // Use SL pattern to load Main Window / Open a different window var serviceLocator = new NinjectServiceLocator(ninjectBootstrapper.Kernel); // Load up Main Window // As you can see, this method still required to pass the Dependencies of the Windows (all the rest will be resolved). // Since a "new" requires the parameters to be passed... //var mainWindow = new WPF.IOC.MainWindow(serviceLocator.GetInstance<IMainService>()); //mainWindow.Show(); // Using this method, we also resolve our Windows (and UserControls) using an IOC-Container var mainWindow2 = serviceLocator.GetInstance <MainWindow>(); mainWindow2.Show(); // The problem with both solutions is that they do not enable design time data on an easy way. // Design time data will be possible, but less easy than with using ViewModels }
private static IMediator BuildMediator() { var kernel = new StandardKernel(); kernel.Components.Add<IBindingResolver, ContravariantBindingResolver>(); kernel.Bind(scan => scan.FromAssemblyContaining<IMediator>().SelectAllClasses().BindDefaultInterface()); kernel.Bind(scan => scan.FromAssemblyContaining<Ping>().SelectAllClasses().BindAllInterfaces()); kernel.Bind<TextWriter>().ToConstant(Console.Out); var serviceLocator = new NinjectServiceLocator(kernel); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); kernel.Bind<ServiceLocatorProvider>().ToConstant(serviceLocatorProvider); var handlers = kernel.GetAll<INotificationHandler<Pinged>>(); var mediator = serviceLocator.GetInstance<IMediator>(); return mediator; }
private static IMediator BuildMediator() { var kernel = new StandardKernel(); kernel.Components.Add <IBindingResolver, ContravariantBindingResolver>(); kernel.Bind(scan => scan.FromAssemblyContaining <IMediator>().SelectAllClasses().BindDefaultInterface()); kernel.Bind(scan => scan.FromAssemblyContaining <Ping>().SelectAllClasses().BindAllInterfaces()); kernel.Bind <TextWriter>().ToConstant(Console.Out); var serviceLocator = new NinjectServiceLocator(kernel); var serviceLocatorProvider = new ServiceLocatorProvider(() => serviceLocator); kernel.Bind <ServiceLocatorProvider>().ToConstant(serviceLocatorProvider); var handlers = kernel.GetAll <INotificationHandler <Pinged> >(); var mediator = serviceLocator.GetInstance <IMediator>(); return(mediator); }