Expose Electron members to the service provider

Used for class composition with IServiceProvider
This commit is contained in:
Dan
2021-01-18 10:58:14 -06:00
parent 3ef44cf878
commit 12f5eae65c
3 changed files with 48 additions and 1 deletions

View File

@@ -0,0 +1,33 @@
using Microsoft.Extensions.DependencyInjection;
namespace ElectronNET.API
{
/// <summary>
///
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds the <see cref="Electron"/> Members to the Service Collection
/// </summary>
public static IServiceCollection AddElectron(this IServiceCollection services)
=> services
// adding in this manner to ensure late binding.
.AddSingleton(provider => IpcMain.Instance)
.AddSingleton(provider => App.Instance)
.AddSingleton(provider => AutoUpdater.Instance)
.AddSingleton(provider => WindowManager.Instance)
.AddSingleton(provider => Menu.Instance)
.AddSingleton(provider => Dialog.Instance)
.AddSingleton(provider => Notification.Instance)
.AddSingleton(provider => Tray.Instance)
.AddSingleton(provider => GlobalShortcut.Instance)
.AddSingleton(provider => Shell.Instance)
.AddSingleton(provider => Screen.Instance)
.AddSingleton(provider => Clipboard.Instance)
.AddSingleton(provider => HostHook.Instance)
.AddSingleton(provider => PowerMonitor.Instance)
.AddSingleton(provider => NativeTheme.Instance)
.AddSingleton(provider => Dock.Instance);
}
}

View File

@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
@@ -36,6 +36,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
buildAll.sh = buildAll.sh
buildReleaseNuGetPackages.cmd = buildReleaseNuGetPackages.cmd
Changelog.md = Changelog.md
README.md = README.md
EndProjectSection
EndProject
Global

View File

@@ -270,3 +270,16 @@ BrowserWindowOptions browserWindowOptions = new BrowserWindowOptions
}
```
### Dependency Injection
ElectronNET.Api can be added to your DI container within the Startup class. All of the modules available in Electron will be added as Singletons.
```csharp
using ElectronNET.API;
public void ConfigureServices(IServiceCollection services)
{
services.AddElectron()
}
```