mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Added routing to UI project
Added Ninject Added Fody
This commit is contained in:
1 parent
fc996b7258
commit
6b8a8b6b4e
14 files changed
+288
-51
No files matched your search
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.UI.Ninject;
|
||||
using Artemis.UI.ViewModels;
|
||||
using Ninject;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Splat;
|
||||
|
||||
namespace Artemis.UI
|
||||
{
|
||||
public class AppBootstrapper : ReactiveObject, IScreen
|
||||
{
|
||||
public AppBootstrapper()
|
||||
{
|
||||
Router = new RoutingState();
|
||||
Kernel = new StandardKernel(new ViewsModule());
|
||||
|
||||
// Configure the Ninject kernel and set it up as the default for ReactiveUI
|
||||
SetupNinject(Kernel);
|
||||
|
||||
// Update the title on view change
|
||||
this.WhenAnyValue(x => x.Router.CurrentViewModel)
|
||||
.Subscribe(o => o.Subscribe(vm => { ViewTitle = vm != null ? vm.UrlPathSegment : ""; }));
|
||||
|
||||
// Navigate to the opening page of the application
|
||||
Router.Navigate.Execute(Kernel.Get<IMainViewModel>());
|
||||
}
|
||||
|
||||
public IKernel Kernel { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string ViewTitle { get; set; }
|
||||
|
||||
public RoutingState Router { get; }
|
||||
|
||||
private void SetupNinject(IKernel kernel)
|
||||
{
|
||||
// Bind the main screen to IScreen
|
||||
kernel.Bind<IScreen>().ToConstant(this);
|
||||
|
||||
// Set up NInject to do DI
|
||||
var customResolver = new FuncDependencyResolver(
|
||||
(service, contract) =>
|
||||
{
|
||||
if (contract != null) return kernel.GetAll(service, contract);
|
||||
var items = kernel.GetAll(service);
|
||||
var list = items.ToList();
|
||||
return list;
|
||||
},
|
||||
(factory, service, contract) =>
|
||||
{
|
||||
var binding = kernel.Bind(service).ToMethod(_ => factory());
|
||||
if (contract != null) binding.Named(contract);
|
||||
});
|
||||
Locator.Current = customResolver;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user