-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathViewModelFactory.cs
More file actions
74 lines (56 loc) · 2.8 KB
/
ViewModelFactory.cs
File metadata and controls
74 lines (56 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics;
using userinterface.Services;
using userinterface.ViewModels.Device;
using userinterface.ViewModels.Mapping;
using userinterface.ViewModels.Profile;
using BE = userspace_backend.Model;
namespace userinterface.Services
{
public class ViewModelFactory : IViewModelFactory
{
public ViewModelFactory(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
}
private IServiceProvider ServiceProvider { get; }
public ProfileViewModel CreateProfileViewModel(BE.IProfileModel profileModel)
{
var stopwatch = Stopwatch.StartNew();
var viewModel = ServiceProvider.GetRequiredService<ProfileViewModel>();
Debug.WriteLine($"ProfileViewModel service resolution: {stopwatch.ElapsedMilliseconds}ms");
stopwatch.Restart();
viewModel.Initialize(profileModel);
Debug.WriteLine($"ProfileViewModel initialize: {stopwatch.ElapsedMilliseconds}ms");
return viewModel;
}
public ProfileSettingsViewModel CreateProfileSettingsViewModel(BE.IProfileModel profileModel)
{
var stopwatch = Stopwatch.StartNew();
var viewModel = ServiceProvider.GetRequiredService<ProfileSettingsViewModel>();
Debug.WriteLine($"ProfileSettingsViewModel service resolution: {stopwatch.ElapsedMilliseconds}ms");
stopwatch.Restart();
viewModel.Initialize(profileModel);
Debug.WriteLine($"ProfileSettingsViewModel initialize: {stopwatch.ElapsedMilliseconds}ms");
return viewModel;
}
public ProfileChartViewModel CreateProfileChartViewModel(BE.IProfileModel profileModel)
{
var stopwatch = Stopwatch.StartNew();
var viewModel = ServiceProvider.GetRequiredService<ProfileChartViewModel>();
Debug.WriteLine($"ProfileChartViewModel service resolution: {stopwatch.ElapsedMilliseconds}ms");
stopwatch.Restart();
viewModel.Initialize(profileModel);
Debug.WriteLine($"ProfileChartViewModel initialize: {stopwatch.ElapsedMilliseconds}ms");
return viewModel;
}
public MappingViewModel CreateMappingViewModel(BE.MappingModel mappingModel, BE.MappingsModel mappingsModel, bool isActive, Action<MappingViewModel> onActivationRequested)
{
var viewModel = ServiceProvider.GetRequiredService<MappingViewModel>();
var modalService = ServiceProvider.GetRequiredService<IModalService>();
viewModel.Initialize(mappingModel, mappingsModel, modalService, isActive, onActivationRequested);
return viewModel;
}
}
}