Further AutoMapper changes

This commit is contained in:
Ben 2015-07-01 22:28:29 +01:00
parent 440254f3f8
commit c3d11da155
2 changed files with 7 additions and 9 deletions

View File

@ -28,8 +28,6 @@ namespace Filtration.ThemeEditor.Providers
public IThemeViewModel NewThemeForScript(ItemFilterScript script) public IThemeViewModel NewThemeForScript(ItemFilterScript script)
{ {
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>();
var themeComponentViewModels = Mapper.Map<ObservableCollection<ThemeComponentViewModel>>(script.ThemeComponents); var themeComponentViewModels = Mapper.Map<ObservableCollection<ThemeComponentViewModel>>(script.ThemeComponents);
var themeViewModel = _themeViewModelFactory.Create(); var themeViewModel = _themeViewModelFactory.Create();
themeViewModel.Initialise(themeComponentViewModels, true); themeViewModel.Initialise(themeComponentViewModels, true);
@ -40,9 +38,6 @@ namespace Filtration.ThemeEditor.Providers
public IThemeViewModel LoadThemeFromFile(string filePath) public IThemeViewModel LoadThemeFromFile(string filePath)
{ {
Mapper.CreateMap<Theme, IThemeViewModel>().ConstructUsingServiceLocator();
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>();
var model = _themePersistenceService.LoadTheme(filePath); var model = _themePersistenceService.LoadTheme(filePath);
var viewModel = Mapper.Map<IThemeViewModel>(model); var viewModel = Mapper.Map<IThemeViewModel>(model);
viewModel.FilePath = filePath; viewModel.FilePath = filePath;
@ -56,9 +51,6 @@ namespace Filtration.ThemeEditor.Providers
public void SaveTheme(IThemeViewModel themeViewModel, string filePath) public void SaveTheme(IThemeViewModel themeViewModel, string filePath)
{ {
Mapper.CreateMap<IThemeViewModel, Theme>();
Mapper.CreateMap<ThemeComponentViewModel, ThemeComponent>();
var theme = Mapper.Map<Theme>(themeViewModel); var theme = Mapper.Map<Theme>(themeViewModel);
_themePersistenceService.SaveTheme(theme, filePath); _themePersistenceService.SaveTheme(theme, filePath);
} }

View File

@ -7,7 +7,9 @@ using Castle.MicroKernel.ModelBuilder.Inspectors;
using Castle.Windsor; using Castle.Windsor;
using Castle.Windsor.Installer; using Castle.Windsor.Installer;
using Filtration.ObjectModel; using Filtration.ObjectModel;
using Filtration.ObjectModel.ThemeEditor;
using Filtration.Properties; using Filtration.Properties;
using Filtration.ThemeEditor.ViewModels;
using Filtration.ViewModels; using Filtration.ViewModels;
using Filtration.Views; using Filtration.Views;
@ -49,7 +51,11 @@ namespace Filtration
opts => opts.MapFrom(from => from)) opts => opts.MapFrom(from => from))
.ForMember(dest => dest.IsExpanded, .ForMember(dest => dest.IsExpanded,
opts => opts.UseValue(false)); opts => opts.UseValue(false));
Mapper.CreateMap<Theme, IThemeViewModel>().ConstructUsingServiceLocator();
Mapper.CreateMap<ThemeComponent, ThemeComponentViewModel>().ReverseMap();
Mapper.CreateMap<IThemeViewModel, Theme>();
Mapper.AssertConfigurationIsValid(); Mapper.AssertConfigurationIsValid();
var mainWindow = _container.Resolve<IMainWindow>(); var mainWindow = _container.Resolve<IMainWindow>();