diff --git a/Directory.Build.props b/Directory.Build.props index 4681de1..7803528 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,6 +3,7 @@ Copyright © Dapplo Dapplo icon.png + README.md https://github.com/dapplo/Dapplo.Microsoft.Extensions git https://github.com/dapplo/Dapplo.Microsoft.Extensions @@ -43,5 +44,7 @@ + + diff --git a/README.md b/README.md index d0d7953..7ccf181 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This repository brings you a few extensions on the generic host which will help - Dapplo.Microsoft.Extensions.Hosting.AppServices - Simple services, e.g. make sure you application runs only once! - Dapplo.Microsoft.Extensions.Hosting.CaliburnMicro - Bases upon Dapplo.Microsoft.Extensions.Hosting.Wpf and bootstraps [Caliburn.Micro](https://caliburnmicro.com) - Dapplo.Microsoft.Extensions.Hosting.WinForms - Have a way to bootstrap Windows Forms with all the possible generic host functionality, and manage the lifetime. -- Dapplo.Microsoft.Extensions.Hosting.Wpf - Have a way to bootstrap WPF with all the possible generic host functionality, and manage the lifetime. +- Dapplo.Microsoft.Extensions.Hosting.Wpf - Have a way to bootstrap WPF with all the possible generic host functionality, and manage the lifetime. - Dapplo.Microsoft.Extensions.Hosting.Plugins - Makes it possible to find & load additional plug-in which can add services to your application. FYI: there is a solution with samples in the samples directory and one which is used on the build server in the src. @@ -28,7 +28,7 @@ Dapplo.Microsoft.Extensions.Hosting.Plugins -------------------------------------------- [![Nuget](https://img.shields.io/nuget/v/Dapplo.Microsoft.Extensions.Hosting.Plugins.svg)](https://www.nuget.org/packages/Dapplo.Microsoft.Extensions.Hosting.Plugins/) -This extension adds plug-in support to generic host based dotnet core 3.0 applications. +This extension adds plug-in support to generic host based dotnet core 6.0 applications. You can simply add the location of plug-ins by specifying globs to find your plug-in assemblies. This can be both files to include and / or exclude. @@ -36,7 +36,7 @@ Each located plug-ins is loaded into it's own AssemblyLoadContext, dependencies [Here](https://github.com/dapplo/Dapplo.Microsoft.Extensions.Hosting/blob/master/samples/Dapplo.Hosting.Sample.ConsoleDemo/Program.cs#L27) is an example how to use the loading, and also how to handle framework assemblies: -``` +```C# .ConfigurePlugins(pluginBuilder => { // Specify the location from where the Dll's are "globbed" @@ -55,7 +55,7 @@ Now you will need to follow a naming convention, this is for speed so there is n Example for the IPlugin implementation, this can configure the HostBuilderContext: -``` +```C# /// /// This plug-in configures the HostBuilderContext to have the hosted services from the online example /// @@ -70,6 +70,16 @@ Example for the IPlugin implementation, this can configure the HostBuilderContex } ``` +This can also be simplified to use the following code with up to 3 configured services: +```C# + /// + /// This plug-in configures the HostBuilderContext to have the hosted services from the online example + /// + public class Plugin : PluginBase + { + } +``` + Dapplo.Microsoft.Extensions.Hosting.AppServices ----------------------------------------------- @@ -79,7 +89,7 @@ This extension adds some generic application services for desktop applications, [Here](https://github.com/dapplo/Dapplo.Microsoft.Extensions.Hosting/blob/master/samples/Dapplo.Hosting.Sample.WinFormsDemo/Program.cs#L25) is an example how to make sure your application only runs once. -``` +```C# .ConfigureSingleInstance(builder => { builder.MutexId = "{B9CE32C0-59AE-4AF0-BE39-5329AAFF4BE8}"; @@ -107,7 +117,7 @@ With this you can enhance your application with a UI, and use all the services p This means you can have a constructor which requests a logger, or other forms. It's not much more than adding something like this to your hostBuilder: -``` +```C# .ConfigureWinForms() .UseWinFormsLifetime() ``` @@ -126,7 +136,7 @@ With this you can enhance your application with a UI, and use all the services p This means your MainWindow can have a constructor which requests a logger, or other windows. It's not much more than adding something like this to your hostBuilder: -``` +```C# .ConfigureWpf() .UseWpfLifetime() ``` @@ -145,7 +155,38 @@ With this you can enhance your application with a UI, and use all the services p This means your MainWindowViewModel can have a constructor which requests a logger, or other windows. It's not much more than adding something like this to your hostBuilder: -``` +```C# .ConfigureCaliburnMicro() ``` It assumes Dapplo.Microsoft.Extensions.Hosting.Wpf is used! + + +Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf +--------------------------------------- + +[![Nuget](https://img.shields.io/nuget/v/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf.svg)](https://www.nuget.org/packages/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/) + +This extension adds [ReactiveUI](https://reactiveui.net/) support to generic host based applications. +With this you can enhance your application with ReactiveUI functions, and use all the services provided by the generic host like combining Splat with Microsoft DI, logging etc, together with this great Reactive MVVM framework. + +This is based on the Dapplo.Microsoft.Extensions.Hosting.Wpf extension, so you can use that to start your application. + +Use the following code to merge ReactiveUI.Splat with the Microsoft Dependency Resolver in your application: +```C# + .ConfigureSplatForMicrosoftDependencyResolver() +``` + +Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms +--------------------------------------- + +[![Nuget](https://img.shields.io/nuget/v/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms.svg)](https://www.nuget.org/packages/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/) + +This extension adds [ReactiveUI](https://reactiveui.net/) support to generic host based applications. +With this you can enhance your application with ReactiveUI functions, and use all the services provided by the generic host like combining Splat with Microsoft DI, logging etc, together with this great Reactive MVVM framework. + +This is based on the Dapplo.Microsoft.Extensions.Hosting.WinForms extension, so you can use that to start your application. + +Use the following code to merge ReactiveUI.Splat with the Microsoft Dependency Resolver in your application: +```C# + .ConfigureSplatForMicrosoftDependencyResolver() +``` diff --git a/samples/Dapplo.Hosting.Sample.PluginOriginalSample/LifetimeEventsHostedService.cs b/samples/Dapplo.Hosting.Sample.PluginOriginalSample/LifetimeEventsHostedService.cs index c7cd294..f1132a2 100644 --- a/samples/Dapplo.Hosting.Sample.PluginOriginalSample/LifetimeEventsHostedService.cs +++ b/samples/Dapplo.Hosting.Sample.PluginOriginalSample/LifetimeEventsHostedService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Dapplo and contributors. All rights reserved. +// Copyright (c) Dapplo and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Threading; @@ -12,7 +12,7 @@ namespace Dapplo.Hosting.Sample.PluginOriginalSample; /// /// Example for a IHostedService which tracks live-time events /// -internal class LifetimeEventsHostedService : IHostedService +public class LifetimeEventsHostedService : IHostedService { private readonly ILogger logger; private readonly IHostApplicationLifetime hostApplicationLifetime; @@ -62,4 +62,4 @@ private void OnStopped() // Perform post-stopped activities here } -} \ No newline at end of file +} diff --git a/samples/Dapplo.Hosting.Sample.PluginOriginalSample/Plugin.cs b/samples/Dapplo.Hosting.Sample.PluginOriginalSample/Plugin.cs index ea51b2f..8abba32 100644 --- a/samples/Dapplo.Hosting.Sample.PluginOriginalSample/Plugin.cs +++ b/samples/Dapplo.Hosting.Sample.PluginOriginalSample/Plugin.cs @@ -2,8 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Dapplo.Microsoft.Extensions.Hosting.Plugins; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; namespace Dapplo.Hosting.Sample.PluginOriginalSample; @@ -11,11 +9,6 @@ namespace Dapplo.Hosting.Sample.PluginOriginalSample; /// This plug-in configures the HostBuilderContext to have the hosted services from the online example /// [PluginOrder(100)] -public class Plugin : IPlugin +public class Plugin : PluginBase { - /// - public void ConfigureHost(HostBuilderContext hostBuilderContext, IServiceCollection serviceCollection) => - serviceCollection - .AddHostedService() - .AddHostedService(); -} \ No newline at end of file +} diff --git a/samples/Dapplo.Hosting.Sample.PluginOriginalSample/TimedHostedService.cs b/samples/Dapplo.Hosting.Sample.PluginOriginalSample/TimedHostedService.cs index b1cb768..dd09f95 100644 --- a/samples/Dapplo.Hosting.Sample.PluginOriginalSample/TimedHostedService.cs +++ b/samples/Dapplo.Hosting.Sample.PluginOriginalSample/TimedHostedService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Dapplo and contributors. All rights reserved. +// Copyright (c) Dapplo and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; @@ -10,7 +10,7 @@ namespace Dapplo.Hosting.Sample.PluginOriginalSample; -internal class TimedHostedService : IHostedService, IDisposable +public class TimedHostedService : IHostedService, IDisposable { private readonly ILogger logger; private Timer timer; @@ -46,4 +46,4 @@ public Task StopAsync(CancellationToken cancellationToken) } public void Dispose() => this.timer?.Dispose(); -} \ No newline at end of file +} diff --git a/samples/Dapplo.Hosting.Sample.PluginWithDependency/MySampleBackgroundService.cs b/samples/Dapplo.Hosting.Sample.PluginWithDependency/MySampleBackgroundService.cs index be87155..07ccc2f 100644 --- a/samples/Dapplo.Hosting.Sample.PluginWithDependency/MySampleBackgroundService.cs +++ b/samples/Dapplo.Hosting.Sample.PluginWithDependency/MySampleBackgroundService.cs @@ -1,4 +1,4 @@ -// Copyright (c) Dapplo and contributors. All rights reserved. +// Copyright (c) Dapplo and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; @@ -14,7 +14,7 @@ namespace Dapplo.Hosting.Sample.PluginWithDependency; /// /// Just some service to run in the background and use a dependency /// -internal class MySampleBackgroundService : IHostedService, IDisposable +public class MySampleBackgroundService : IHostedService, IDisposable { private readonly ILogger logger; private Timer timer; @@ -66,4 +66,4 @@ public void Dispose() { this.timer?.Dispose(); } -} \ No newline at end of file +} diff --git a/samples/Dapplo.Hosting.Sample.PluginWithDependency/Plugin.cs b/samples/Dapplo.Hosting.Sample.PluginWithDependency/Plugin.cs index f812b4d..e204a77 100644 --- a/samples/Dapplo.Hosting.Sample.PluginWithDependency/Plugin.cs +++ b/samples/Dapplo.Hosting.Sample.PluginWithDependency/Plugin.cs @@ -2,8 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Dapplo.Microsoft.Extensions.Hosting.Plugins; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; namespace Dapplo.Hosting.Sample.PluginWithDependency; @@ -11,8 +9,6 @@ namespace Dapplo.Hosting.Sample.PluginWithDependency; /// A simple plugin definition, registering the BackgroundService /// [PluginOrder(-1)] -public class Plugin : IPlugin +public class Plugin : PluginBase { - /// - public void ConfigureHost(HostBuilderContext hostBuilderContext, IServiceCollection serviceCollection) => serviceCollection.AddHostedService(); -} \ No newline at end of file +} diff --git a/samples/Dapplo.Hosting.Sample.ReactiveDemo/Dapplo.Hosting.Sample.ReactiveDemo.csproj b/samples/Dapplo.Hosting.Sample.ReactiveDemo/Dapplo.Hosting.Sample.ReactiveDemo.csproj index c4cfc7d..e5ad064 100644 --- a/samples/Dapplo.Hosting.Sample.ReactiveDemo/Dapplo.Hosting.Sample.ReactiveDemo.csproj +++ b/samples/Dapplo.Hosting.Sample.ReactiveDemo/Dapplo.Hosting.Sample.ReactiveDemo.csproj @@ -13,15 +13,13 @@ - - - + diff --git a/samples/Dapplo.Hosting.Sample.ReactiveDemo/Program.cs b/samples/Dapplo.Hosting.Sample.ReactiveDemo/Program.cs index fbf3134..0759317 100644 --- a/samples/Dapplo.Hosting.Sample.ReactiveDemo/Program.cs +++ b/samples/Dapplo.Hosting.Sample.ReactiveDemo/Program.cs @@ -1,19 +1,20 @@ // Copyright (c) Dapplo and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Dapplo.Microsoft.Extensions.Hosting.Plugins; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using System; using System.IO; -using Dapplo.Microsoft.Extensions.Hosting.AppServices; using System.Threading.Tasks; +using Dapplo.Microsoft.Extensions.Hosting.AppServices; +using Dapplo.Microsoft.Extensions.Hosting.Plugins; +using Dapplo.Microsoft.Extensions.Hosting.ReactiveUI; +using Dapplo.Microsoft.Extensions.Hosting.Wpf; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using ReactiveUI; -using Splat.Microsoft.Extensions.DependencyInjection; using Splat; -using Dapplo.Microsoft.Extensions.Hosting.Wpf; +using Splat.Microsoft.Extensions.DependencyInjection; namespace Dapplo.Hosting.Sample.ReactiveDemo; @@ -27,6 +28,7 @@ public static Task Main(string[] args) { var executableLocation = Path.GetDirectoryName(typeof(Program).Assembly.Location) ?? throw new NotSupportedException("Can't start without location."); var host = new HostBuilder() + .ConfigureSplatForMicrosoftDependencyResolver() .ConfigureWpf(wpfBuilder => wpfBuilder.UseWindow()) .ConfigureLogging() .ConfigureConfiguration(args) diff --git a/samples/Dapplo.Hosting.Samples.sln b/samples/Dapplo.Hosting.Samples.sln index 2b4b3e5..47e5e12 100644 --- a/samples/Dapplo.Hosting.Samples.sln +++ b/samples/Dapplo.Hosting.Samples.sln @@ -35,10 +35,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Hosting.Sample.React EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Microsoft.Extensions.Hosting.UiThread", "..\src\Dapplo.Microsoft.Extensions.Hosting.UiThread\Dapplo.Microsoft.Extensions.Hosting.UiThread.csproj", "{CF56B3E8-7119-46EB-9F98-04002B6A52BC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapplo.Hosting.Sample.DefaultWpfDemo", "Dapplo.Hosting.Sample.DefaultWpfDemo\Dapplo.Hosting.Sample.DefaultWpfDemo.csproj", "{3F568DEE-DBB8-411F-8320-6D1200980E00}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Hosting.Sample.DefaultWpfDemo", "Dapplo.Hosting.Sample.DefaultWpfDemo\Dapplo.Hosting.Sample.DefaultWpfDemo.csproj", "{3F568DEE-DBB8-411F-8320-6D1200980E00}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{BD536381-4FC0-4FAC-ABEE-AA70CE491341}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf", "..\src\Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf\Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf.csproj", "{24A22E74-D68D-43A6-A520-74171C77439E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms", "..\src\Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms\Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms.csproj", "{4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -183,6 +187,22 @@ Global {3F568DEE-DBB8-411F-8320-6D1200980E00}.Release|Any CPU.Build.0 = Release|Any CPU {3F568DEE-DBB8-411F-8320-6D1200980E00}.Release|x64.ActiveCfg = Release|Any CPU {3F568DEE-DBB8-411F-8320-6D1200980E00}.Release|x64.Build.0 = Release|Any CPU + {24A22E74-D68D-43A6-A520-74171C77439E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {24A22E74-D68D-43A6-A520-74171C77439E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24A22E74-D68D-43A6-A520-74171C77439E}.Debug|x64.ActiveCfg = Debug|Any CPU + {24A22E74-D68D-43A6-A520-74171C77439E}.Debug|x64.Build.0 = Debug|Any CPU + {24A22E74-D68D-43A6-A520-74171C77439E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {24A22E74-D68D-43A6-A520-74171C77439E}.Release|Any CPU.Build.0 = Release|Any CPU + {24A22E74-D68D-43A6-A520-74171C77439E}.Release|x64.ActiveCfg = Release|Any CPU + {24A22E74-D68D-43A6-A520-74171C77439E}.Release|x64.Build.0 = Release|Any CPU + {4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}.Debug|x64.ActiveCfg = Debug|Any CPU + {4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}.Debug|x64.Build.0 = Debug|Any CPU + {4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}.Release|Any CPU.Build.0 = Release|Any CPU + {4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}.Release|x64.ActiveCfg = Release|Any CPU + {4E3E2A5B-B19A-4ED4-BC1E-6355A077A102}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.Plugins/PluginBase.cs b/src/Dapplo.Microsoft.Extensions.Hosting.Plugins/PluginBase.cs new file mode 100644 index 0000000..6498252 --- /dev/null +++ b/src/Dapplo.Microsoft.Extensions.Hosting.Plugins/PluginBase.cs @@ -0,0 +1,50 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Dapplo.Microsoft.Extensions.Hosting.Plugins; + +/// +/// Plugin Base. +/// +/// The type of Plugin. +/// +public class PluginBase : IPlugin + where T : class, IHostedService +{ + /// + public void ConfigureHost(HostBuilderContext hostBuilderContext, IServiceCollection serviceCollection) => + serviceCollection.AddHostedService(); +} + +/// +/// Plugin Base. +/// +/// The type of the 1st Plugin. +/// The type of the 2nd Plugin. +/// +public class PluginBase : IPlugin + where T1 : class, IHostedService + where T2 : class, IHostedService +{ + /// + public void ConfigureHost(HostBuilderContext hostBuilderContext, IServiceCollection serviceCollection) => + serviceCollection.AddHostedService().AddHostedService(); +} + +/// +/// Plugin Base. +/// +/// The type of the 1st Plugin. +/// The type of the 2nd Plugin. +/// The type of the 3rd Plugin. +/// +/// +public class PluginBase : IPlugin + where T1 : class, IHostedService + where T2 : class, IHostedService + where T3 : class, IHostedService +{ + /// + public void ConfigureHost(HostBuilderContext hostBuilderContext, IServiceCollection serviceCollection) => + serviceCollection.AddHostedService().AddHostedService().AddHostedService(); +} diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms.csproj b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms.csproj new file mode 100644 index 0000000..6739b32 --- /dev/null +++ b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms.csproj @@ -0,0 +1,20 @@ + + + + + net472;net6.0-windows10.0.17763;net7.0-windows10.0.17763 + true + This extension adds ReactiveUI support to generic host based dotnet core 6.0 / 7.0 WinForms applications. With this you can enhance your application with a UI, and use all the services provided by the generic host like DI, logging etc, together with this reactive MVVM framework. + + + + + + + + + + + + + diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/FodyWeavers.xsd b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/FodyWeavers.xsd new file mode 100644 index 0000000..f3ac476 --- /dev/null +++ b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/FodyWeavers.xsd @@ -0,0 +1,26 @@ + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/HostBuilderReactiveUiExtensions.cs b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/HostBuilderReactiveUiExtensions.cs new file mode 100644 index 0000000..c5ccae3 --- /dev/null +++ b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms/HostBuilderReactiveUiExtensions.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.Extensions.Hosting; +using ReactiveUI; +using Splat; +using Splat.Microsoft.Extensions.DependencyInjection; + +namespace Dapplo.Microsoft.Extensions.Hosting.ReactiveUI; + +/// +/// This contains the ReactiveUi extensions for Microsoft.Extensions.Hosting. +/// +public static class HostBuilderReactiveUiExtensions +{ + /// + /// Configure a ReactiveUI application. + /// + /// IHostBuilder. + /// I Host Builder. + public static IHostBuilder ConfigureSplatForMicrosoftDependencyResolver(this IHostBuilder hostBuilder) => + hostBuilder.ConfigureServices((serviceCollection) => + { + serviceCollection.UseMicrosoftDependencyResolver(); + var resolver = Locator.CurrentMutable; + resolver.InitializeSplat(); + resolver.InitializeReactiveUI(); + }); + + /// + /// Maps the splat locator to the IServiceProvider. + /// + /// The host. + /// The IServiceProvider factory. + /// A Value. + public static IHost MapSplatLocator(this IHost host, Action containerFactory) + { + var c = host.Services; + c.UseMicrosoftDependencyResolver(); + containerFactory.Invoke(c); + return host; + } +} diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf.csproj b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf.csproj new file mode 100644 index 0000000..3072544 --- /dev/null +++ b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf.csproj @@ -0,0 +1,20 @@ + + + + + net472;net6.0-windows10.0.17763;net7.0-windows10.0.17763 + true + This extension adds ReactiveUI support to generic host based dotnet core 6.0 / 7.0 WPF applications. With this you can enhance your application with a UI, and use all the services provided by the generic host like DI, logging etc, together with this reactive MVVM framework. + + + + + + + + + + + + + diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/FodyWeavers.xml b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/FodyWeavers.xml new file mode 100644 index 0000000..63fc148 --- /dev/null +++ b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/FodyWeavers.xsd b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/FodyWeavers.xsd new file mode 100644 index 0000000..f3ac476 --- /dev/null +++ b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/FodyWeavers.xsd @@ -0,0 +1,26 @@ + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/HostBuilderReactiveUiExtensions.cs b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/HostBuilderReactiveUiExtensions.cs new file mode 100644 index 0000000..c5ccae3 --- /dev/null +++ b/src/Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf/HostBuilderReactiveUiExtensions.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.Extensions.Hosting; +using ReactiveUI; +using Splat; +using Splat.Microsoft.Extensions.DependencyInjection; + +namespace Dapplo.Microsoft.Extensions.Hosting.ReactiveUI; + +/// +/// This contains the ReactiveUi extensions for Microsoft.Extensions.Hosting. +/// +public static class HostBuilderReactiveUiExtensions +{ + /// + /// Configure a ReactiveUI application. + /// + /// IHostBuilder. + /// I Host Builder. + public static IHostBuilder ConfigureSplatForMicrosoftDependencyResolver(this IHostBuilder hostBuilder) => + hostBuilder.ConfigureServices((serviceCollection) => + { + serviceCollection.UseMicrosoftDependencyResolver(); + var resolver = Locator.CurrentMutable; + resolver.InitializeSplat(); + resolver.InitializeReactiveUI(); + }); + + /// + /// Maps the splat locator to the IServiceProvider. + /// + /// The host. + /// The IServiceProvider factory. + /// A Value. + public static IHost MapSplatLocator(this IHost host, Action containerFactory) + { + var c = host.Services; + c.UseMicrosoftDependencyResolver(); + containerFactory.Invoke(c); + return host; + } +} diff --git a/src/Dapplo.Microsoft.Extensions.Hosting.sln b/src/Dapplo.Microsoft.Extensions.Hosting.sln index 3856403..d10173e 100644 --- a/src/Dapplo.Microsoft.Extensions.Hosting.sln +++ b/src/Dapplo.Microsoft.Extensions.Hosting.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28711.60 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33516.290 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Microsoft.Extensions.Hosting.Plugins", "Dapplo.Microsoft.Extensions.Hosting.Plugins\Dapplo.Microsoft.Extensions.Hosting.Plugins.csproj", "{021F054E-F3E0-44AB-AF4A-042A7513B2D6}" EndProject @@ -17,6 +17,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Microsoft.Extensions EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Microsoft.Extensions.Hosting.UiThread", "Dapplo.Microsoft.Extensions.Hosting.UiThread\Dapplo.Microsoft.Extensions.Hosting.UiThread.csproj", "{C71BD377-5E95-44E5-A099-53C97AD897B9}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionConfig", "SolutionConfig", "{B2596DF3-5720-41B9-900C-28593556EFAC}" + ProjectSection(SolutionItems) = preProject + ..\.editorconfig = ..\.editorconfig + ..\.gitattributes = ..\.gitattributes + ..\.gitignore = ..\.gitignore + ..\azure-pipelines.yml = ..\azure-pipelines.yml + ..\CODE_OF_CONDUCT.md = ..\CODE_OF_CONDUCT.md + ..\contributing.md = ..\contributing.md + ..\Directory.Build.props = ..\Directory.Build.props + ..\global.json = ..\global.json + ..\LICENSE = ..\LICENSE + ..\README.md = ..\README.md + ..\version.json = ..\version.json + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf", "Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf\Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf.csproj", "{AA74E656-A5EE-415D-AA19-40222A63F615}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms", "Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms\Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.WinForms.csproj", "{3D74C743-4361-4125-A56E-B9F26F9B7747}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -81,6 +100,22 @@ Global {C71BD377-5E95-44E5-A099-53C97AD897B9}.Release|Any CPU.Build.0 = Release|Any CPU {C71BD377-5E95-44E5-A099-53C97AD897B9}.Release|x64.ActiveCfg = Release|Any CPU {C71BD377-5E95-44E5-A099-53C97AD897B9}.Release|x64.Build.0 = Release|Any CPU + {AA74E656-A5EE-415D-AA19-40222A63F615}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA74E656-A5EE-415D-AA19-40222A63F615}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA74E656-A5EE-415D-AA19-40222A63F615}.Debug|x64.ActiveCfg = Debug|Any CPU + {AA74E656-A5EE-415D-AA19-40222A63F615}.Debug|x64.Build.0 = Debug|Any CPU + {AA74E656-A5EE-415D-AA19-40222A63F615}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA74E656-A5EE-415D-AA19-40222A63F615}.Release|Any CPU.Build.0 = Release|Any CPU + {AA74E656-A5EE-415D-AA19-40222A63F615}.Release|x64.ActiveCfg = Release|Any CPU + {AA74E656-A5EE-415D-AA19-40222A63F615}.Release|x64.Build.0 = Release|Any CPU + {3D74C743-4361-4125-A56E-B9F26F9B7747}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D74C743-4361-4125-A56E-B9F26F9B7747}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D74C743-4361-4125-A56E-B9F26F9B7747}.Debug|x64.ActiveCfg = Debug|Any CPU + {3D74C743-4361-4125-A56E-B9F26F9B7747}.Debug|x64.Build.0 = Debug|Any CPU + {3D74C743-4361-4125-A56E-B9F26F9B7747}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D74C743-4361-4125-A56E-B9F26F9B7747}.Release|Any CPU.Build.0 = Release|Any CPU + {3D74C743-4361-4125-A56E-B9F26F9B7747}.Release|x64.ActiveCfg = Release|Any CPU + {3D74C743-4361-4125-A56E-B9F26F9B7747}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE