forked from OpenTabletDriver/OpenTabletDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesktopServiceCollection.cs
58 lines (55 loc) · 2.49 KB
/
DesktopServiceCollection.cs
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
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.Threading;
using Octokit;
using OpenTabletDriver.ComponentProviders;
using OpenTabletDriver.Components;
using OpenTabletDriver.Configurations;
using OpenTabletDriver.Desktop.Components;
using OpenTabletDriver.Desktop.Diagnostics;
using OpenTabletDriver.Desktop.Interop;
using OpenTabletDriver.Desktop.Reflection;
using OpenTabletDriver.Devices;
using OpenTabletDriver.Interop;
namespace OpenTabletDriver.Desktop
{
using static ServiceDescriptor;
public class DesktopServiceCollection : ServiceCollection
{
public DesktopServiceCollection()
{
this.AddServices(new[]
{
// Core Services
Singleton<SynchronizationContext>(_ => new NonConcurrentSynchronizationContext(false)),
Singleton<IDriver, Driver>(),
Singleton<IReportParserProvider, ReportParserProvider>(),
Singleton<IDeviceHubsProvider, DeviceHubsProvider>(p => new DeviceHubsProvider(p)),
Singleton<ICompositeDeviceHub, RootHub>(RootHub.WithProvider),
Singleton<IDeviceConfigurationProvider, DesktopDeviceConfigurationProvider>(),
Singleton<IReportParserProvider, DesktopReportParserProvider>(),
// Desktop Services
Singleton<IGitHubClient>(new GitHubClient(ProductHeaderValue.Parse("OpenTabletDriver"))),
Transient<EnvironmentDictionary, EnvironmentDictionary>(),
Singleton<IPluginManager, PluginManager>(),
Singleton<ISettingsManager, SettingsManager>(),
Singleton<IPresetManager, PresetManager>(),
Singleton<IPluginFactory, PluginFactory>(),
Singleton<ISleepDetector, SleepDetector>(),
Transient(p => p.GetRequiredService<ISettingsManager>().Settings)
});
}
public static DesktopServiceCollection GetPlatformServiceCollection()
{
return SystemInterop.CurrentPlatform switch
{
SystemPlatform.Windows => new DesktopWindowsServiceCollection(),
SystemPlatform.Linux => new DesktopLinuxServiceCollection(),
SystemPlatform.MacOS => new DesktopMacOSServiceCollection(),
_ => throw new PlatformNotSupportedException("This platform is not supported by OpenTabletDriver.")
};
}
}
}