-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
37 lines (30 loc) · 1.37 KB
/
Program.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
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Reflection;
using TouchPortalSDK.Configuration;
using TPMuteMe;
Assembly assembly = Assembly.GetExecutingAssembly();
String baseDirectory = Path.GetDirectoryName(assembly.Location)!;
// Build configuration:
IConfigurationRoot configurationRoot = new ConfigurationBuilder()
.SetBasePath(baseDirectory)
.AddJsonFile("appsettings.json")
.Build();
// Standard method for build a ServiceProvider in .Net:
ServiceCollection serviceCollection = new ServiceCollection();
// Add logging
serviceCollection.AddLogging(configure =>
{
configure.AddSimpleConsole(options => options.TimestampFormat = "[yyyy.MM.dd HH:mm:ss] ");
configure.AddConfiguration(configurationRoot.GetSection("Logging"));
});
// Registering the Plugin to the IoC container:
serviceCollection.AddTouchPortalSdk(configurationRoot);
serviceCollection.AddSingleton<MuteMePlugin>();
serviceCollection.AddSingleton<MuteMe>();
// Use your IoC framework to resolve the plugin with it's dependencies,
ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(true);
MuteMePlugin plugin = serviceProvider.GetRequiredService<MuteMePlugin>();
// Run it
plugin.Run();