diff --git a/ElectronNET.API/ServiceCollectionExtensions.cs b/ElectronNET.API/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..f933731 --- /dev/null +++ b/ElectronNET.API/ServiceCollectionExtensions.cs @@ -0,0 +1,33 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace ElectronNET.API +{ + /// + /// + /// + public static class ServiceCollectionExtensions + { + /// + /// Adds the Members to the Service Collection + /// + 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); + } +} diff --git a/ElectronNET.sln b/ElectronNET.sln index eed5a6d..ac12c06 100644 --- a/ElectronNET.sln +++ b/ElectronNET.sln @@ -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 diff --git a/README.md b/README.md index 78cdee7..60903ac 100644 --- a/README.md +++ b/README.md @@ -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() +} +```