ViewModelLocator is now responsible for connecting view models to views.
Uses an auto-wiring convention-based approach.
This commit is contained in:
parent
721e35f724
commit
efa81cf842
@ -1,6 +1,6 @@
|
|||||||
using eShopOnContainers.Core.Helpers;
|
using eShopOnContainers.Core.Helpers;
|
||||||
using eShopOnContainers.Services;
|
using eShopOnContainers.Services;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using Xamarin.Forms.Xaml;
|
using Xamarin.Forms.Xaml;
|
||||||
@ -27,13 +27,13 @@ namespace eShopOnContainers
|
|||||||
private void InitApp()
|
private void InitApp()
|
||||||
{
|
{
|
||||||
UseMockServices = Settings.UseMocks;
|
UseMockServices = Settings.UseMocks;
|
||||||
|
ViewModelLocator.Initialize();
|
||||||
ViewModelLocator.Instance.UpdateDependencies(UseMockServices);
|
ViewModelLocator.UpdateDependencies(UseMockServices);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task InitNavigation()
|
private Task InitNavigation()
|
||||||
{
|
{
|
||||||
var navigationService = ViewModelLocator.Instance.Resolve<INavigationService>();
|
var navigationService = ViewModelLocator.Resolve<INavigationService>();
|
||||||
return navigationService.InitializeAsync();
|
return navigationService.InitializeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using eShopOnContainers.Core.Models.Basket;
|
using eShopOnContainers.Core.Models.Basket;
|
||||||
using eShopOnContainers.Core.Models.Catalog;
|
using eShopOnContainers.Core.Models.Catalog;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@ -21,7 +21,7 @@ namespace eShopOnContainers.Core.Helpers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!ViewModelLocator.Instance.UseMockService
|
if (!ViewModelLocator.UseMockService
|
||||||
&& Settings.UrlBase != GlobalSetting.DefaultEndpoint)
|
&& Settings.UrlBase != GlobalSetting.DefaultEndpoint)
|
||||||
{
|
{
|
||||||
foreach (var catalogItem in catalogItems)
|
foreach (var catalogItem in catalogItems)
|
||||||
@ -54,7 +54,7 @@ namespace eShopOnContainers.Core.Helpers
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!ViewModelLocator.Instance.UseMockService
|
if (!ViewModelLocator.UseMockService
|
||||||
&& Settings.UrlBase != GlobalSetting.DefaultEndpoint)
|
&& Settings.UrlBase != GlobalSetting.DefaultEndpoint)
|
||||||
{
|
{
|
||||||
foreach (var basketItem in basketItems)
|
foreach (var basketItem in basketItems)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using Plugin.Settings;
|
using Plugin.Settings;
|
||||||
using Plugin.Settings.Abstractions;
|
using Plugin.Settings.Abstractions;
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ namespace eShopOnContainers.Core.Helpers
|
|||||||
private const string IdUrlBase = "url_base";
|
private const string IdUrlBase = "url_base";
|
||||||
private static readonly string AccessTokenDefault = string.Empty;
|
private static readonly string AccessTokenDefault = string.Empty;
|
||||||
private static readonly string IdTokenDefault = string.Empty;
|
private static readonly string IdTokenDefault = string.Empty;
|
||||||
private static readonly bool UseMocksDefault = ViewModelLocator.Instance.UseMockService;
|
private static readonly bool UseMocksDefault = ViewModelLocator.UseMockService;
|
||||||
private static readonly string UrlBaseDefault = GlobalSetting.Instance.BaseEndpoint;
|
private static readonly string UrlBaseDefault = GlobalSetting.Instance.BaseEndpoint;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
using eShopOnContainers.Core.Helpers;
|
using eShopOnContainers.Core.Helpers;
|
||||||
using eShopOnContainers.Core.ViewModels;
|
using eShopOnContainers.Core.ViewModels;
|
||||||
using eShopOnContainers.Core.Views;
|
using eShopOnContainers.Core.Views;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
@ -11,8 +12,6 @@ namespace eShopOnContainers.Services
|
|||||||
{
|
{
|
||||||
public class NavigationService : INavigationService
|
public class NavigationService : INavigationService
|
||||||
{
|
{
|
||||||
protected readonly Dictionary<Type, Type> _mappings;
|
|
||||||
|
|
||||||
protected Application CurrentApplication
|
protected Application CurrentApplication
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -21,13 +20,6 @@ namespace eShopOnContainers.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavigationService()
|
|
||||||
{
|
|
||||||
_mappings = new Dictionary<Type, Type>();
|
|
||||||
|
|
||||||
CreatePageViewModelMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task InitializeAsync()
|
public Task InitializeAsync()
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(Settings.AuthAccessToken))
|
if(string.IsNullOrEmpty(Settings.AuthAccessToken))
|
||||||
@ -100,7 +92,7 @@ namespace eShopOnContainers.Services
|
|||||||
|
|
||||||
protected virtual async Task InternalNavigateToAsync(Type viewModelType, object parameter)
|
protected virtual async Task InternalNavigateToAsync(Type viewModelType, object parameter)
|
||||||
{
|
{
|
||||||
Page page = CreateAndBindPage(viewModelType, parameter);
|
Page page = CreatePage(viewModelType, parameter);
|
||||||
|
|
||||||
if (page is LoginView)
|
if (page is LoginView)
|
||||||
{
|
{
|
||||||
@ -109,7 +101,6 @@ namespace eShopOnContainers.Services
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var navigationPage = CurrentApplication.MainPage as CustomNavigationView;
|
var navigationPage = CurrentApplication.MainPage as CustomNavigationView;
|
||||||
|
|
||||||
if (navigationPage != null)
|
if (navigationPage != null)
|
||||||
{
|
{
|
||||||
await navigationPage.PushAsync(page);
|
await navigationPage.PushAsync(page);
|
||||||
@ -123,42 +114,25 @@ namespace eShopOnContainers.Services
|
|||||||
await (page.BindingContext as ViewModelBase).InitializeAsync(parameter);
|
await (page.BindingContext as ViewModelBase).InitializeAsync(parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Type GetPageTypeForViewModel(Type viewModelType)
|
protected Type GetPageTypeForViewModel(Type viewModelType)
|
||||||
{
|
{
|
||||||
if (!_mappings.ContainsKey(viewModelType))
|
var viewName = viewModelType.FullName.Replace("Model", string.Empty);
|
||||||
{
|
var viewModelAssemblyName = viewModelType.GetTypeInfo().Assembly.FullName;
|
||||||
throw new KeyNotFoundException($"No map for ${viewModelType} was found on navigation mappings");
|
var viewAssemblyName = string.Format(CultureInfo.InvariantCulture, "{0}, {1}", viewName, viewModelAssemblyName);
|
||||||
}
|
var viewType = Type.GetType(viewAssemblyName);
|
||||||
|
return viewType;
|
||||||
|
}
|
||||||
|
|
||||||
return _mappings[viewModelType];
|
protected Page CreatePage(Type viewModelType, object parameter)
|
||||||
}
|
{
|
||||||
|
Type pageType = GetPageTypeForViewModel(viewModelType);
|
||||||
|
if (pageType == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"Cannot locate page type for {viewModelType}");
|
||||||
|
}
|
||||||
|
|
||||||
protected Page CreateAndBindPage(Type viewModelType, object parameter)
|
Page page = Activator.CreateInstance(pageType) as Page;
|
||||||
{
|
return page;
|
||||||
Type pageType = GetPageTypeForViewModel(viewModelType);
|
}
|
||||||
|
|
||||||
if (pageType == null)
|
|
||||||
{
|
|
||||||
throw new Exception($"Mapping type for {viewModelType} is not a page");
|
|
||||||
}
|
|
||||||
|
|
||||||
Page page = Activator.CreateInstance(pageType) as Page;
|
|
||||||
ViewModelBase viewModel = ViewModelLocator.Instance.Resolve(viewModelType) as ViewModelBase;
|
|
||||||
page.BindingContext = viewModel;
|
|
||||||
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreatePageViewModelMappings()
|
|
||||||
{
|
|
||||||
_mappings.Add(typeof(BasketViewModel), typeof(BasketView));
|
|
||||||
_mappings.Add(typeof(CatalogViewModel), typeof(CatalogView));
|
|
||||||
_mappings.Add(typeof(CheckoutViewModel), typeof(CheckoutView));
|
|
||||||
_mappings.Add(typeof(LoginViewModel), typeof(LoginView));
|
|
||||||
_mappings.Add(typeof(MainViewModel), typeof(MainView));
|
|
||||||
_mappings.Add(typeof(OrderDetailViewModel), typeof(OrderDetailView));
|
|
||||||
_mappings.Add(typeof(ProfileViewModel), typeof(ProfileView));
|
|
||||||
_mappings.Add(typeof(SettingsViewModel), typeof(SettingsView));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -3,7 +3,7 @@ using System.Linq.Expressions;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace eShopOnContainers.ViewModels.Base
|
namespace eShopOnContainers.Core.ViewModels.Base
|
||||||
{
|
{
|
||||||
public abstract class ExtendedBindableObject : BindableObject
|
public abstract class ExtendedBindableObject : BindableObject
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
using eShopOnContainers.Core;
|
using eShopOnContainers.Core.Helpers;
|
||||||
using eShopOnContainers.Core.Helpers;
|
|
||||||
using eShopOnContainers.Services;
|
using eShopOnContainers.Services;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace eShopOnContainers.ViewModels.Base
|
namespace eShopOnContainers.Core.ViewModels.Base
|
||||||
{
|
{
|
||||||
public abstract class ViewModelBase : ExtendedBindableObject
|
public abstract class ViewModelBase : ExtendedBindableObject
|
||||||
{
|
{
|
||||||
@ -28,8 +27,8 @@ namespace eShopOnContainers.ViewModels.Base
|
|||||||
|
|
||||||
public ViewModelBase()
|
public ViewModelBase()
|
||||||
{
|
{
|
||||||
DialogService = ViewModelLocator.Instance.Resolve<IDialogService>();
|
DialogService = ViewModelLocator.Resolve<IDialogService>();
|
||||||
NavigationService = ViewModelLocator.Instance.Resolve<INavigationService>();
|
NavigationService = ViewModelLocator.Resolve<INavigationService>();
|
||||||
GlobalSetting.Instance.BaseEndpoint = Settings.UrlBase;
|
GlobalSetting.Instance.BaseEndpoint = Settings.UrlBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
using Microsoft.Practices.Unity;
|
using Microsoft.Practices.Unity;
|
||||||
using eShopOnContainers.Core.ViewModels;
|
|
||||||
using eShopOnContainers.Services;
|
using eShopOnContainers.Services;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
using eShopOnContainers.Core.Services.Catalog;
|
using eShopOnContainers.Core.Services.Catalog;
|
||||||
using eShopOnContainers.Core.Services.OpenUrl;
|
using eShopOnContainers.Core.Services.OpenUrl;
|
||||||
using eShopOnContainers.Core.Services.RequestProvider;
|
using eShopOnContainers.Core.Services.RequestProvider;
|
||||||
@ -9,100 +10,101 @@ using eShopOnContainers.Core.Services.Basket;
|
|||||||
using eShopOnContainers.Core.Services.Identity;
|
using eShopOnContainers.Core.Services.Identity;
|
||||||
using eShopOnContainers.Core.Services.Order;
|
using eShopOnContainers.Core.Services.Order;
|
||||||
using eShopOnContainers.Core.Services.User;
|
using eShopOnContainers.Core.Services.User;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace eShopOnContainers.ViewModels.Base
|
namespace eShopOnContainers.Core.ViewModels.Base
|
||||||
{
|
{
|
||||||
public class ViewModelLocator
|
public static class ViewModelLocator
|
||||||
{
|
{
|
||||||
private bool _useMockService;
|
private static readonly IUnityContainer _unityContainer = new UnityContainer();
|
||||||
private readonly IUnityContainer _unityContainer;
|
|
||||||
|
|
||||||
private static readonly ViewModelLocator _instance = new ViewModelLocator();
|
public static readonly BindableProperty AutoWireViewModelProperty =
|
||||||
|
BindableProperty.CreateAttached("AutoWireViewModel", typeof(bool), typeof(ViewModelLocator), default(bool), propertyChanged: OnAutoWireViewModelChanged);
|
||||||
|
|
||||||
public static ViewModelLocator Instance
|
public static bool GetAutoWireViewModel(BindableObject bindable)
|
||||||
{
|
{
|
||||||
get { return _instance; }
|
return (bool)bindable.GetValue(ViewModelLocator.AutoWireViewModelProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UseMockService
|
public static void SetAutoWireViewModel(BindableObject bindable, bool value)
|
||||||
{
|
{
|
||||||
get { return _useMockService; }
|
bindable.SetValue(ViewModelLocator.AutoWireViewModelProperty, value);
|
||||||
set { _useMockService = value; ; }
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected ViewModelLocator()
|
public static bool UseMockService { get; set; }
|
||||||
{
|
|
||||||
_unityContainer = new UnityContainer();
|
|
||||||
|
|
||||||
// Services
|
public static void Initialize()
|
||||||
_unityContainer.RegisterType<IDialogService, DialogService>();
|
{
|
||||||
RegisterSingleton<INavigationService, NavigationService>();
|
// Services
|
||||||
_unityContainer.RegisterType<IOpenUrlService, OpenUrlService>();
|
_unityContainer.RegisterType<IDialogService, DialogService>();
|
||||||
_unityContainer.RegisterType<IRequestProvider, RequestProvider>();
|
_unityContainer.RegisterType<INavigationService, NavigationService>(new ContainerControlledLifetimeManager());
|
||||||
_unityContainer.RegisterType<IIdentityService, IdentityService>();
|
_unityContainer.RegisterType<IOpenUrlService, OpenUrlService>();
|
||||||
|
_unityContainer.RegisterType<IRequestProvider, RequestProvider>();
|
||||||
|
_unityContainer.RegisterType<IIdentityService, IdentityService>();
|
||||||
|
_unityContainer.RegisterType<ICatalogService, CatalogMockService>();
|
||||||
|
_unityContainer.RegisterType<IBasketService, BasketMockService>();
|
||||||
|
_unityContainer.RegisterType<IUserService, UserMockService>();
|
||||||
|
|
||||||
_unityContainer.RegisterType<ICatalogService, CatalogMockService>();
|
// View models
|
||||||
_unityContainer.RegisterType<IBasketService, BasketMockService>();
|
_unityContainer.RegisterType<BasketViewModel>();
|
||||||
_unityContainer.RegisterType<IUserService, UserMockService>();
|
_unityContainer.RegisterType<CatalogViewModel>();
|
||||||
|
_unityContainer.RegisterType<CheckoutViewModel>();
|
||||||
|
_unityContainer.RegisterType<LoginViewModel>();
|
||||||
|
_unityContainer.RegisterType<MainViewModel>();
|
||||||
|
_unityContainer.RegisterType<OrderDetailViewModel>();
|
||||||
|
_unityContainer.RegisterType<ProfileViewModel>();
|
||||||
|
_unityContainer.RegisterType<SettingsViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
// View models
|
public static void UpdateDependencies(bool useMockServices)
|
||||||
_unityContainer.RegisterType<BasketViewModel>();
|
{
|
||||||
_unityContainer.RegisterType<CatalogViewModel>();
|
// Change injected dependencies
|
||||||
_unityContainer.RegisterType<CheckoutViewModel>();
|
if (useMockServices)
|
||||||
_unityContainer.RegisterType<LoginViewModel>();
|
{
|
||||||
_unityContainer.RegisterType<MainViewModel>();
|
_unityContainer.RegisterInstance<ICatalogService>(new CatalogMockService());
|
||||||
_unityContainer.RegisterType<OrderDetailViewModel>();
|
_unityContainer.RegisterInstance<IBasketService>(new BasketMockService());
|
||||||
_unityContainer.RegisterType<ProfileViewModel>();
|
_unityContainer.RegisterInstance<IOrderService>(new OrderMockService());
|
||||||
_unityContainer.RegisterType<SettingsViewModel>();
|
_unityContainer.RegisterInstance<IUserService>(new UserMockService());
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateDependencies(bool useMockServices)
|
UseMockService = true;
|
||||||
{
|
}
|
||||||
// Change injected dependencies
|
else
|
||||||
if (useMockServices)
|
{
|
||||||
{
|
var requestProvider = Resolve<IRequestProvider>();
|
||||||
_unityContainer.RegisterInstance<ICatalogService>(new CatalogMockService());
|
_unityContainer.RegisterInstance<ICatalogService>(new CatalogService(requestProvider));
|
||||||
_unityContainer.RegisterInstance<IBasketService>(new BasketMockService());
|
_unityContainer.RegisterInstance<IBasketService>(new BasketService(requestProvider));
|
||||||
_unityContainer.RegisterInstance<IOrderService>(new OrderMockService());
|
_unityContainer.RegisterInstance<IOrderService>(new OrderService(requestProvider));
|
||||||
_unityContainer.RegisterInstance<IUserService>(new UserMockService());
|
_unityContainer.RegisterInstance<IUserService>(new UserService(requestProvider));
|
||||||
|
|
||||||
UseMockService = true;
|
UseMockService = false;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
var requestProvider = Resolve<IRequestProvider>();
|
|
||||||
_unityContainer.RegisterInstance<ICatalogService>(new CatalogService(requestProvider));
|
|
||||||
_unityContainer.RegisterInstance<IBasketService>(new BasketService(requestProvider));
|
|
||||||
_unityContainer.RegisterInstance<IOrderService>(new OrderService(requestProvider));
|
|
||||||
_unityContainer.RegisterInstance<IUserService>(new UserService(requestProvider));
|
|
||||||
|
|
||||||
UseMockService = false;
|
public static T Resolve<T>()
|
||||||
}
|
{
|
||||||
}
|
return _unityContainer.Resolve<T>();
|
||||||
|
}
|
||||||
public T Resolve<T>()
|
|
||||||
{
|
|
||||||
return _unityContainer.Resolve<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Resolve(Type type)
|
private static void OnAutoWireViewModelChanged(BindableObject bindable, object oldValue, object newValue)
|
||||||
{
|
{
|
||||||
return _unityContainer.Resolve(type);
|
var view = bindable as Element;
|
||||||
}
|
if (view == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public void Register<T>(T instance)
|
var viewType = view.GetType();
|
||||||
{
|
var viewName = viewType.FullName.Replace(".Views.", ".ViewModels.");
|
||||||
_unityContainer.RegisterInstance<T>(instance);
|
var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;
|
||||||
}
|
var viewModelName = string.Format(CultureInfo.InvariantCulture, "{0}Model, {1}", viewName, viewAssemblyName);
|
||||||
|
|
||||||
public void Register<TInterface, T>() where T : TInterface
|
var viewModelType = Type.GetType(viewModelName);
|
||||||
{
|
if (viewModelType == null)
|
||||||
_unityContainer.RegisterType<TInterface, T>();
|
{
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
public void RegisterSingleton<TInterface, T>() where T : TInterface
|
var viewModel = _unityContainer.Resolve(viewModelType);
|
||||||
{
|
view.BindingContext = viewModel;
|
||||||
_unityContainer.RegisterType<TInterface, T>(new ContainerControlledLifetimeManager());
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -4,8 +4,6 @@ using eShopOnContainers.Core.Models.Catalog;
|
|||||||
using eShopOnContainers.Core.Services.Basket;
|
using eShopOnContainers.Core.Services.Basket;
|
||||||
using eShopOnContainers.Core.Services.User;
|
using eShopOnContainers.Core.Services.User;
|
||||||
using eShopOnContainers.Core.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
|
||||||
using System;
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using eShopOnContainers.Core.ViewModels.Base;
|
|
||||||
using eShopOnContainers.Core.Models.Catalog;
|
using eShopOnContainers.Core.Models.Catalog;
|
||||||
using eShopOnContainers.Core.Services.Catalog;
|
using eShopOnContainers.Core.Services.Catalog;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Linq;
|
|
||||||
using eShopOnContainers.Core.Services.Basket;
|
using eShopOnContainers.Core.Services.Basket;
|
||||||
using eShopOnContainers.Core.Helpers;
|
|
||||||
using eShopOnContainers.Core.Services.User;
|
using eShopOnContainers.Core.Services.User;
|
||||||
|
|
||||||
namespace eShopOnContainers.Core.ViewModels
|
namespace eShopOnContainers.Core.ViewModels
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using eShopOnContainers.Core.Models.Navigation;
|
using eShopOnContainers.Core.Models.Navigation;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -138,7 +138,7 @@ namespace eShopOnContainers.Core.ViewModels
|
|||||||
await _basketService.ClearBasketAsync(_shippingAddress.Id.ToString(), authToken);
|
await _basketService.ClearBasketAsync(_shippingAddress.Id.ToString(), authToken);
|
||||||
|
|
||||||
// Reset Basket badge
|
// Reset Basket badge
|
||||||
var basketViewModel = ViewModelLocator.Instance.Resolve<BasketViewModel>();
|
var basketViewModel = ViewModelLocator.Resolve<BasketViewModel>();
|
||||||
basketViewModel.BadgeCount = 0;
|
basketViewModel.BadgeCount = 0;
|
||||||
|
|
||||||
// Navigate to Orders
|
// Navigate to Orders
|
||||||
|
@ -4,7 +4,7 @@ using eShopOnContainers.Core.Services.Identity;
|
|||||||
using eShopOnContainers.Core.Services.OpenUrl;
|
using eShopOnContainers.Core.Services.OpenUrl;
|
||||||
using eShopOnContainers.Core.Services.User;
|
using eShopOnContainers.Core.Services.User;
|
||||||
using eShopOnContainers.Core.Validations;
|
using eShopOnContainers.Core.Validations;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using IdentityModel.Client;
|
using IdentityModel.Client;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using eShopOnContainers.Core.Models.Navigation;
|
using eShopOnContainers.Core.Models.Navigation;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using eShopOnContainers.Core.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using eShopOnContainers.Core.Models.Orders;
|
using eShopOnContainers.Core.Models.Orders;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using eShopOnContainers.Core.Services.Catalog;
|
using eShopOnContainers.Core.Services.Catalog;
|
||||||
using eShopOnContainers.Core.Services.Basket;
|
using eShopOnContainers.Core.Services.Basket;
|
||||||
using eShopOnContainers.Core.Services.Order;
|
using eShopOnContainers.Core.Services.Order;
|
||||||
|
@ -3,7 +3,7 @@ using eShopOnContainers.Core.Helpers;
|
|||||||
using eShopOnContainers.Core.Models.Orders;
|
using eShopOnContainers.Core.Models.Orders;
|
||||||
using eShopOnContainers.Core.Models.User;
|
using eShopOnContainers.Core.Models.User;
|
||||||
using eShopOnContainers.Core.Services.Order;
|
using eShopOnContainers.Core.Services.Order;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using eShopOnContainers.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -71,7 +71,7 @@ namespace eShopOnContainers.Core.ViewModels
|
|||||||
|
|
||||||
private void MockServices()
|
private void MockServices()
|
||||||
{
|
{
|
||||||
ViewModelLocator.Instance.UpdateDependencies(!UseAzureServices);
|
ViewModelLocator.UpdateDependencies(!UseAzureServices);
|
||||||
UpdateInfo();
|
UpdateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.BasketView"
|
x:Class="eShopOnContainers.Core.Views.BasketView"
|
||||||
|
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||||
Title="Cart">
|
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||||
|
Title="Cart">
|
||||||
<ContentPage.Resources>
|
<ContentPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.CatalogView"
|
x:Class="eShopOnContainers.Core.Views.CatalogView"
|
||||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||||
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
||||||
|
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||||
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
||||||
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
||||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||||
|
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||||
Title="Catalog">
|
Title="Catalog">
|
||||||
<ContentPage.Resources>
|
<ContentPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.CheckoutView"
|
x:Class="eShopOnContainers.Core.Views.CheckoutView"
|
||||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||||
|
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||||
|
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||||
Title="Checkout">
|
Title="Checkout">
|
||||||
<ContentPage.Resources>
|
<ContentPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.LoginView"
|
x:Class="eShopOnContainers.Core.Views.LoginView"
|
||||||
|
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||||
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
||||||
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
||||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core">
|
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||||
|
viewModelBase:ViewModelLocator.AutoWireViewModel="true">
|
||||||
<ContentPage.Title>
|
<ContentPage.Title>
|
||||||
<OnPlatform
|
<OnPlatform
|
||||||
x:TypeArguments="x:String"
|
x:TypeArguments="x:String"
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.MainView"
|
x:Class="eShopOnContainers.Core.Views.MainView"
|
||||||
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
||||||
|
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||||
xmlns:controls="clr-namespace:eShopOnContainers.Core.Controls;assembly=eShopOnContainers.Core"
|
xmlns:controls="clr-namespace:eShopOnContainers.Core.Controls;assembly=eShopOnContainers.Core"
|
||||||
BarBackgroundColor="{StaticResource DarkGreenColor}"
|
BarBackgroundColor="{StaticResource DarkGreenColor}"
|
||||||
BackgroundColor="{StaticResource BackgroundColor}"
|
BackgroundColor="{StaticResource BackgroundColor}"
|
||||||
BarTextColor="{StaticResource WhiteColor}">
|
BarTextColor="{StaticResource WhiteColor}"
|
||||||
|
viewModelBase:ViewModelLocator.AutoWireViewModel="true">
|
||||||
<TabbedPage.Title>
|
<TabbedPage.Title>
|
||||||
<OnPlatform
|
<OnPlatform
|
||||||
x:TypeArguments="x:String"
|
x:TypeArguments="x:String"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using eShopOnContainers.Core.ViewModels;
|
using eShopOnContainers.Core.ViewModels;
|
||||||
using eShopOnContainers.Core.ViewModels.Base;
|
using eShopOnContainers.Core.ViewModels.Base;
|
||||||
using eShopOnContainers.ViewModels.Base;
|
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace eShopOnContainers.Core.Views
|
namespace eShopOnContainers.Core.Views
|
||||||
@ -32,17 +31,9 @@ namespace eShopOnContainers.Core.Views
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var homeViewModel = ViewModelLocator.Instance.Resolve<CatalogViewModel>();
|
await ((CatalogViewModel)HomeView.BindingContext).InitializeAsync(null);
|
||||||
await homeViewModel.InitializeAsync(null);
|
await ((BasketViewModel)BasketView.BindingContext).InitializeAsync(null);
|
||||||
HomeView.BindingContext = homeViewModel;
|
await ((ProfileViewModel)ProfileView.BindingContext).InitializeAsync(null);
|
||||||
|
|
||||||
var basketViewModel = ViewModelLocator.Instance.Resolve<BasketViewModel>();
|
|
||||||
await basketViewModel.InitializeAsync(null);
|
|
||||||
BasketView.BindingContext = basketViewModel;
|
|
||||||
|
|
||||||
var profileViewModel = ViewModelLocator.Instance.Resolve<ProfileViewModel>();
|
|
||||||
await profileViewModel.InitializeAsync(null);
|
|
||||||
ProfileView.BindingContext = profileViewModel;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.OrderDetailView"
|
x:Class="eShopOnContainers.Core.Views.OrderDetailView"
|
||||||
|
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||||
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
||||||
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
||||||
|
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||||
Title="{Binding Order.OrderNumber}">
|
Title="{Binding Order.OrderNumber}">
|
||||||
<ContentPage.Resources>
|
<ContentPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.ProfileView"
|
x:Class="eShopOnContainers.Core.Views.ProfileView"
|
||||||
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
xmlns:views="clr-namespace:eShopOnContainers.Core.Views;assembly=eShopOnContainers.Core"
|
||||||
|
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||||
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
xmlns:templates="clr-namespace:eShopOnContainers.Core.Views.Templates;assembly=eShopOnContainers.Core"
|
||||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||||
|
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||||
Title="My profile">
|
Title="My profile">
|
||||||
<ContentPage.Resources>
|
<ContentPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="eShopOnContainers.Core.Views.SettingsView"
|
x:Class="eShopOnContainers.Core.Views.SettingsView"
|
||||||
|
xmlns:viewModelBase="clr-namespace:eShopOnContainers.Core.ViewModels.Base;assembly=eShopOnContainers.Core"
|
||||||
xmlns:controls="clr-namespace:eShopOnContainers.Core.Controls;assembly=eShopOnContainers.Core"
|
xmlns:controls="clr-namespace:eShopOnContainers.Core.Controls;assembly=eShopOnContainers.Core"
|
||||||
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
xmlns:animations="clr-namespace:eShopOnContainers.Core.Animations;assembly=eShopOnContainers.Core"
|
||||||
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
xmlns:triggers="clr-namespace:eShopOnContainers.Core.Triggers;assembly=eShopOnContainers.Core"
|
||||||
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
xmlns:behaviors="clr-namespace:eShopOnContainers.Core.Behaviors;assembly=eShopOnContainers.Core"
|
||||||
|
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
|
||||||
Title="Settings">
|
Title="Settings">
|
||||||
<ContentPage.Resources>
|
<ContentPage.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user