/*
In App.xaml:
In the View:
DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
You can also use Blend to do all this with the tool's support.
See http://www.galasoft.ch/mvvm
*/
using System;
using CommonServiceLocator;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.ViewModels.Settings;
using ModernKeePass.Domain.Interfaces;
namespace ModernKeePass.ViewModels
{
///
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
///
public class ViewModelLocatorCommon
{
///
/// Initializes a new instance of the ViewModelLocator class.
///
public ViewModelLocatorCommon()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic)
{
// Create design time view services and models
//SimpleIoc.Default.Register();
}
else
{
// Create run time view services and models
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
SimpleIoc.Default.Register(() => App.Services.GetRequiredService());
}
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
}
public SecurityVm Security => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public SettingsNewVm SettingsNew => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public GeneralVm General => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public CredentialsVm Credentials => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public RecycleBinVm RecycleBin => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public HistoryVm History => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public OpenDatabaseControlVm OpenDatabaseControl => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public SetCredentialsVm SetCredentials => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public TopMenuVm TopMenu => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public ColorPickerControlVm ColorPicker => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public PasswordGenerationBoxControlVm PasswordGenerationBox => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public BreadcrumbControlVm Breadcrumb => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public NewVm New => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public OpenVm Open => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public RecentVm Recent => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public SaveVm Save => ServiceLocator.Current.GetInstance(Guid.NewGuid().ToString());
public static void Cleanup()
{
// TODO Clear the ViewModels
SimpleIoc.Default.Reset();
}
}
}