Skip to content

Commit 12f5eae

Browse files
DanDan
authored andcommitted
Expose Electron members to the service provider
Used for class composition with IServiceProvider
1 parent 3ef44cf commit 12f5eae

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace ElectronNET.API
4+
{
5+
/// <summary>
6+
///
7+
/// </summary>
8+
public static class ServiceCollectionExtensions
9+
{
10+
/// <summary>
11+
/// Adds the <see cref="Electron"/> Members to the Service Collection
12+
/// </summary>
13+
public static IServiceCollection AddElectron(this IServiceCollection services)
14+
=> services
15+
// adding in this manner to ensure late binding.
16+
.AddSingleton(provider => IpcMain.Instance)
17+
.AddSingleton(provider => App.Instance)
18+
.AddSingleton(provider => AutoUpdater.Instance)
19+
.AddSingleton(provider => WindowManager.Instance)
20+
.AddSingleton(provider => Menu.Instance)
21+
.AddSingleton(provider => Dialog.Instance)
22+
.AddSingleton(provider => Notification.Instance)
23+
.AddSingleton(provider => Tray.Instance)
24+
.AddSingleton(provider => GlobalShortcut.Instance)
25+
.AddSingleton(provider => Shell.Instance)
26+
.AddSingleton(provider => Screen.Instance)
27+
.AddSingleton(provider => Clipboard.Instance)
28+
.AddSingleton(provider => HostHook.Instance)
29+
.AddSingleton(provider => PowerMonitor.Instance)
30+
.AddSingleton(provider => NativeTheme.Instance)
31+
.AddSingleton(provider => Dock.Instance);
32+
}
33+
}

ElectronNET.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.27130.2027
@@ -36,6 +36,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
3636
buildAll.sh = buildAll.sh
3737
buildReleaseNuGetPackages.cmd = buildReleaseNuGetPackages.cmd
3838
Changelog.md = Changelog.md
39+
README.md = README.md
3940
EndProjectSection
4041
EndProject
4142
Global

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,16 @@ BrowserWindowOptions browserWindowOptions = new BrowserWindowOptions
270270
}
271271

272272
```
273+
274+
### Dependency Injection
275+
276+
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.
277+
278+
```csharp
279+
using ElectronNET.API;
280+
281+
public void ConfigureServices(IServiceCollection services)
282+
{
283+
services.AddElectron()
284+
}
285+
```

0 commit comments

Comments
 (0)