4a4fc708c7
Add AutoMapper and INotifyPropertyChanged to enable cart quantity changes to be reflected
88 lines
2.7 KiB
C#
88 lines
2.7 KiB
C#
using AutoMapper;
|
|
using Caliburn.Micro;
|
|
using RMWPFInterfaceLibrary.Api;
|
|
using RMWPFInterfaceLibrary.Helpers;
|
|
using RMWPFInterfaceLibrary.Models;
|
|
using RMWPFUserInterface.Helpers;
|
|
using RMWPFUserInterface.Models;
|
|
using RMWPFUserInterface.ViewModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace RMWPFUserInterface
|
|
{
|
|
internal class BootStrapper : BootstrapperBase
|
|
{
|
|
private SimpleContainer _container = new SimpleContainer();
|
|
public BootStrapper()
|
|
{
|
|
Initialize();
|
|
|
|
ConventionManager.AddElementConvention<PasswordBox>(
|
|
PasswordBoxHelper.BoundPasswordProperty,
|
|
"Password",
|
|
"PasswordChanged");
|
|
}
|
|
protected override void Configure()
|
|
{
|
|
_container.Instance(ConfigureAutoMapper());
|
|
|
|
_container.Instance(_container)
|
|
.PerRequest<IProductEndPoint, ProductEndPoint>()
|
|
.PerRequest<ISaleEndPoint, SaleEndPoint>();
|
|
|
|
_container
|
|
.Singleton<IWindowManager, WindowManager>()
|
|
.Singleton<IEventAggregator, EventAggregator>()
|
|
.Singleton<ILoggedInUserModel, LoggedInUserModel>()
|
|
.Singleton<IConfigHelper, ConfigHelper>()
|
|
.Singleton<IAPIHelper, APIHelper>();
|
|
|
|
GetType().Assembly.GetTypes()
|
|
.Where(type => type.IsClass)
|
|
.Where(type => type.Name.EndsWith("ViewModel"))
|
|
.ToList()
|
|
.ForEach(viewModelType => _container.RegisterPerRequest(
|
|
viewModelType, viewModelType.ToString(), viewModelType));
|
|
}
|
|
|
|
private IMapper ConfigureAutoMapper()
|
|
{
|
|
var config = new MapperConfiguration(cfg =>
|
|
{
|
|
cfg.CreateMap<ProductModel, ProductDisplayModel>();
|
|
cfg.CreateMap<CartItemModel, CartItemDisplayModel>();
|
|
});
|
|
|
|
var output = config.CreateMapper();
|
|
|
|
return output;
|
|
}
|
|
|
|
protected override void OnStartup(object sender, StartupEventArgs e)
|
|
{
|
|
DisplayRootViewForAsync<ShellViewModel>();
|
|
}
|
|
|
|
protected override object GetInstance(Type service, string key)
|
|
{
|
|
return _container.GetInstance(service, key);
|
|
}
|
|
|
|
protected override IEnumerable<object> GetAllInstances(Type service)
|
|
{
|
|
return _container.GetAllInstances(service);
|
|
}
|
|
|
|
protected override void BuildUp(object instance)
|
|
{
|
|
_container.BuildUp(instance);
|
|
}
|
|
}
|
|
}
|