diff --git a/Mystify/App.axaml.cs b/Mystify/App.axaml.cs index 4f881d5..3d20ab1 100644 --- a/Mystify/App.axaml.cs +++ b/Mystify/App.axaml.cs @@ -7,7 +7,6 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; -using Lib.Audio.Factories; using Lib.NotifyIcon; using LightweightIocContainer.Interfaces; using Mystify.ViewModels; @@ -31,10 +30,10 @@ namespace Mystify Bootstrapper bootstrapper = new(); _kernel = bootstrapper.BootstrapKernel(); - //FixMe + MainModel mainModel = _kernel.Resolve(); _mainWindow = new MainWindow { - DataContext = new MainWindowViewModel(_kernel.Resolve(), _kernel.Resolve()) + DataContext = new MainWindowViewModel(mainModel) }; if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopStyleApplicationLifetime) diff --git a/Mystify/Bootstrapper.cs b/Mystify/Bootstrapper.cs index 895423c..6827b22 100644 --- a/Mystify/Bootstrapper.cs +++ b/Mystify/Bootstrapper.cs @@ -12,6 +12,7 @@ namespace Mystify { public IIocContainer BootstrapKernel() => new IocContainer().Install( + new MainInstaller(), new NotifyIconInstaller(), new AudioInstaller(), new MidiInstaller()); diff --git a/Mystify/Installers/MainInstaller.cs b/Mystify/Installers/MainInstaller.cs new file mode 100644 index 0000000..be2dffd --- /dev/null +++ b/Mystify/Installers/MainInstaller.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/Mystify/MainModel.cs b/Mystify/MainModel.cs new file mode 100644 index 0000000..7f44725 --- /dev/null +++ b/Mystify/MainModel.cs @@ -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 Channels => _device.Channels; + public List Controllables => _controllableCollector.Controllables; + } +} \ No newline at end of file diff --git a/Mystify/ViewModels/MainWindowViewModel.cs b/Mystify/ViewModels/MainWindowViewModel.cs index 73a10da..96d985f 100644 --- a/Mystify/ViewModels/MainWindowViewModel.cs +++ b/Mystify/ViewModels/MainWindowViewModel.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Windows.Input; -using Lib.Audio.Factories; using Lib.Audio.Interfaces; using ReactiveUI; @@ -13,28 +12,18 @@ namespace Mystify.ViewModels { public class MainWindowViewModel : ViewModelBase { - private readonly IDevice _device; + private readonly MainModel? _mainModel; public MainWindowViewModel() { if (!IsInDesignMode) throw new InvalidOperationException("Constructor is for design time usage only."); - - Channels = new List(); - Controllables = new List(); } - public MainWindowViewModel(IDeviceFactory deviceFactory, IControllableCollectorFactory controllableCollectorFactory) - { - _device = deviceFactory.Create(); - IControllableCollector controllableCollector = controllableCollectorFactory.Create(); - - Channels = _device.Channels; - Controllables = controllableCollector.Controllables; - } + public MainWindowViewModel(MainModel mainModel) => _mainModel = mainModel; - public List Channels { get; } - public List Controllables { get; } + public List? Channels => _mainModel?.Channels; + public List? Controllables => _mainModel?.Controllables; public IChannel? SelectedChannel { get; set; } public IControllable? SelectedControllable { get; set; }