< Summary

Information
Class: MyNet.UI.ViewModels.ServiceCollectionExtensions
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Extensions/ServiceCollectionExtensions.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 90
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddShell(...)100%11100%
AddShellPreferences(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Extensions/ServiceCollectionExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ServiceCollectionExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System.Collections.Generic;
 8using System.Globalization;
 9using Microsoft.Extensions.DependencyInjection;
 10using Microsoft.Extensions.DependencyInjection.Extensions;
 11using MyNet.Globalization.Culture;
 12using MyNet.UI.Commands;
 13using MyNet.UI.Dialogs.ContentDialogs;
 14using MyNet.UI.Loading;
 15using MyNet.UI.Services;
 16using MyNet.UI.ViewModels.Preferences;
 17using MyNet.UI.ViewModels.Shell;
 18using MyNet.UI.ViewModels.Shell.About;
 19using MyNet.UI.ViewModels.Shell.Chrome;
 20using MyNet.UI.ViewModels.Shell.Drawers;
 21using MyNet.UI.ViewModels.Shell.FileMenu;
 22using MyNet.UI.ViewModels.Shell.Host;
 23using MyNet.UI.ViewModels.Shell.Notifications;
 24using MyNet.UI.ViewModels.Shell.Services;
 25using MyNet.UI.ViewModels.Shell.Startup;
 26using MyNet.UI.ViewModels.Shell.Taskbar;
 27
 28#pragma warning disable IDE0130
 29namespace MyNet.UI.ViewModels;
 30#pragma warning restore IDE0130
 31
 32/// <summary>
 33/// DI registration helpers for view models.
 34/// </summary>
 35public static class ServiceCollectionExtensions
 36{
 37    extension(IServiceCollection services)
 38    {
 39        /// <summary>
 40        /// Registers shell services and panel view models.
 41        /// Call after <c>AddDialogs()</c> so <see cref="ShellDrawerCoordinator"/> can subscribe to content dialog event
 42        /// Register <see cref="ShellHostViewModel"/> in the host application (pass <see cref="FileMenuViewModel"/> when
 43        /// </summary>
 44        public IServiceCollection AddShell(IEnumerable<CultureInfo>? supportedCultures = null)
 45        {
 646            services.TryAddSingleton<IApplicationInfo, ApplicationInfo>();
 647            services.TryAddSingleton<IShellHostProvider, ShellHostProvider>();
 648            services.TryAddSingleton<ShellService>();
 649            services.TryAddSingleton<IShellService>(static sp => sp.GetRequiredService<ShellService>());
 650            services.TryAddSingleton<IShellDrawerService>(static sp => sp.GetRequiredService<ShellService>());
 651            services.TryAddSingleton<IShellFileMenuService>(static sp => sp.GetRequiredService<ShellService>());
 652            services.TryAddSingleton<IFileMenuViewModelFactory, FileMenuViewModelFactory>();
 53
 654            services.TryAddTransient<ShellNotificationsViewModel>();
 655            services.TryAddTransient(sp => new ShellCultureViewModel(sp.GetRequiredService<ICultureService>(), sp.GetSer
 656            services.TryAddTransient<ShellThemeViewModel>();
 657            services.TryAddTransient<SplashScreenViewModel>();
 658            services.TryAddTransient<AboutViewModel>();
 59
 660            services.TryAddSingleton<ITaskbarProgressSource, TaskbarProgressSource>();
 661            services.TryAddSingleton<BusyTaskbarCoordinator>(static sp =>
 662                new(
 663                    sp.GetRequiredService<IBusyService>(),
 664                    sp.GetRequiredService<ITaskbarProgressSource>()));
 65
 666            services.TryAddSingleton<ShellNotificationsDrawerCoordinator>();
 667            services.TryAddSingleton<ShellDrawerCoordinator>(static sp =>
 668            {
 669                _ = sp.GetRequiredService<IShellHostProvider>();
 670                return new(
 671                    sp.GetRequiredService<IContentDialogService>(),
 672                    sp.GetRequiredService<IShellHostProvider>());
 673            });
 74
 675            return services;
 76        }
 77
 78        /// <summary>
 79        /// Registers preferences page view models used by the shell preferences workspace.
 80        /// Register <see cref="PreferencesViewModel"/> in the host with the desired page list.
 81        /// </summary>
 82        public IServiceCollection AddShellPreferences()
 83        {
 384            services.TryAddTransient<DisplayPreferencesViewModel>();
 385            services.TryAddTransient<TimeAndLanguagePreferencesViewModel>();
 386            return services;
 87        }
 88    }
 89}
 90