- add main model

master
Simon G 5 years ago
parent 12c0e6a539
commit 4462056745
  1. 5
      Mystify/App.axaml.cs
  2. 1
      Mystify/Bootstrapper.cs
  3. 17
      Mystify/Installers/MainInstaller.cs
  4. 25
      Mystify/MainModel.cs
  5. 19
      Mystify/ViewModels/MainWindowViewModel.cs

@ -7,7 +7,6 @@ using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Lib.Audio.Factories;
using Lib.NotifyIcon; using Lib.NotifyIcon;
using LightweightIocContainer.Interfaces; using LightweightIocContainer.Interfaces;
using Mystify.ViewModels; using Mystify.ViewModels;
@ -31,10 +30,10 @@ namespace Mystify
Bootstrapper bootstrapper = new(); Bootstrapper bootstrapper = new();
_kernel = bootstrapper.BootstrapKernel(); _kernel = bootstrapper.BootstrapKernel();
//FixMe MainModel mainModel = _kernel.Resolve<MainModel>();
_mainWindow = new MainWindow _mainWindow = new MainWindow
{ {
DataContext = new MainWindowViewModel(_kernel.Resolve<IDeviceFactory>(), _kernel.Resolve<IControllableCollectorFactory>()) DataContext = new MainWindowViewModel(mainModel)
}; };
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopStyleApplicationLifetime) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopStyleApplicationLifetime)

@ -12,6 +12,7 @@ namespace Mystify
{ {
public IIocContainer BootstrapKernel() => public IIocContainer BootstrapKernel() =>
new IocContainer().Install( new IocContainer().Install(
new MainInstaller(),
new NotifyIconInstaller(), new NotifyIconInstaller(),
new AudioInstaller(), new AudioInstaller(),
new MidiInstaller()); new MidiInstaller());

@ -0,0 +1,17 @@
// Author: Gockner, Simon
// Created: 2021-04-09
// Copyright(c) 2021 SimonG. All Rights Reserved.
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Installers;
namespace Mystify.Installers
{
public class MainInstaller : IIocInstaller
{
public void Install(IIocContainer container)
{
container.Register<MainModel>();
}
}
}

@ -0,0 +1,25 @@
// Author: Gockner, Simon
// Created: 2021-04-09
// Copyright(c) 2021 SimonG. All Rights Reserved.
using System.Collections.Generic;
using Lib.Audio.Factories;
using Lib.Audio.Interfaces;
namespace Mystify
{
public class MainModel
{
private readonly IDevice _device;
private readonly IControllableCollector _controllableCollector;
public MainModel(IDeviceFactory deviceFactory, IControllableCollectorFactory controllableCollectorFactory)
{
_device = deviceFactory.Create();
_controllableCollector = controllableCollectorFactory.Create();
}
public List<IChannel> Channels => _device.Channels;
public List<IControllable> Controllables => _controllableCollector.Controllables;
}
}

@ -5,7 +5,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Input; using System.Windows.Input;
using Lib.Audio.Factories;
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using ReactiveUI; using ReactiveUI;
@ -13,28 +12,18 @@ namespace Mystify.ViewModels
{ {
public class MainWindowViewModel : ViewModelBase public class MainWindowViewModel : ViewModelBase
{ {
private readonly IDevice _device; private readonly MainModel? _mainModel;
public MainWindowViewModel() public MainWindowViewModel()
{ {
if (!IsInDesignMode) if (!IsInDesignMode)
throw new InvalidOperationException("Constructor is for design time usage only."); throw new InvalidOperationException("Constructor is for design time usage only.");
Channels = new List<IChannel>();
Controllables = new List<IControllable>();
} }
public MainWindowViewModel(IDeviceFactory deviceFactory, IControllableCollectorFactory controllableCollectorFactory) public MainWindowViewModel(MainModel mainModel) => _mainModel = mainModel;
{
_device = deviceFactory.Create();
IControllableCollector controllableCollector = controllableCollectorFactory.Create();
Channels = _device.Channels;
Controllables = controllableCollector.Controllables;
}
public List<IChannel> Channels { get; } public List<IChannel>? Channels => _mainModel?.Channels;
public List<IControllable> Controllables { get; } public List<IControllable>? Controllables => _mainModel?.Controllables;
public IChannel? SelectedChannel { get; set; } public IChannel? SelectedChannel { get; set; }
public IControllable? SelectedControllable { get; set; } public IControllable? SelectedControllable { get; set; }

Loading…
Cancel
Save