Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Master to WinUI #46

Merged
merged 7 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<Copyright>Copyright © Dapplo</Copyright>
<Authors>Dapplo</Authors>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/dapplo/Dapplo.Microsoft.Extensions</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/dapplo/Dapplo.Microsoft.Extensions</PackageProjectUrl>
Expand Down Expand Up @@ -43,5 +44,7 @@
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
<None Include="$(SolutionDir)\icon.png" Pack="true" PackagePath="\"/>
<None Include="$(MSBuildThisFileDirectory)LICENSE" Pack="true" PackagePath="LICENSE" />
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
57 changes: 49 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -28,15 +28,15 @@ 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.
Each located plug-ins is loaded into it's own AssemblyLoadContext, dependencies are found and loaded in the same AssemblyLoadContext via an AssemblyDependencyResolver (which was introduced in dotnet core 3.0).

[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"
Expand All @@ -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#
/// <summary>
/// This plug-in configures the HostBuilderContext to have the hosted services from the online example
/// </summary>
Expand All @@ -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#
/// <summary>
/// This plug-in configures the HostBuilderContext to have the hosted services from the online example
/// </summary>
public class Plugin : PluginBase<LifetimeEventsHostedService, TimedHostedService>
{
}
```


Dapplo.Microsoft.Extensions.Hosting.AppServices
-----------------------------------------------
Expand All @@ -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}";
Expand Down Expand Up @@ -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<Form1>()
.UseWinFormsLifetime()
```
Expand All @@ -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<MainWindow>()
.UseWpfLifetime()
```
Expand All @@ -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<MainViewModel>()
```
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()
```
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,7 @@ namespace Dapplo.Hosting.Sample.PluginOriginalSample;
/// <summary>
/// Example for a IHostedService which tracks live-time events
/// </summary>
internal class LifetimeEventsHostedService : IHostedService
public class LifetimeEventsHostedService : IHostedService
{
private readonly ILogger logger;
private readonly IHostApplicationLifetime hostApplicationLifetime;
Expand Down Expand Up @@ -62,4 +62,4 @@ private void OnStopped()

// Perform post-stopped activities here
}
}
}
11 changes: 2 additions & 9 deletions samples/Dapplo.Hosting.Sample.PluginOriginalSample/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@
// 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;

/// <summary>
/// This plug-in configures the HostBuilderContext to have the hosted services from the online example
/// </summary>
[PluginOrder(100)]
public class Plugin : IPlugin
public class Plugin : PluginBase<LifetimeEventsHostedService, TimedHostedService>
{
/// <inheritdoc />
public void ConfigureHost(HostBuilderContext hostBuilderContext, IServiceCollection serviceCollection) =>
serviceCollection
.AddHostedService<LifetimeEventsHostedService>()
.AddHostedService<TimedHostedService>();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -46,4 +46,4 @@ public Task StopAsync(CancellationToken cancellationToken)
}

public void Dispose() => this.timer?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +14,7 @@ namespace Dapplo.Hosting.Sample.PluginWithDependency;
/// <summary>
/// Just some service to run in the background and use a dependency
/// </summary>
internal class MySampleBackgroundService : IHostedService, IDisposable
public class MySampleBackgroundService : IHostedService, IDisposable
{
private readonly ILogger logger;
private Timer timer;
Expand Down Expand Up @@ -66,4 +66,4 @@ public void Dispose()
{
this.timer?.Dispose();
}
}
}
8 changes: 2 additions & 6 deletions samples/Dapplo.Hosting.Sample.PluginWithDependency/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
// 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;

/// <summary>
/// A simple plugin definition, registering the BackgroundService
/// </summary>
[PluginOrder(-1)]
public class Plugin : IPlugin
public class Plugin : PluginBase<MySampleBackgroundService>
{
/// <inheritdoc />
public void ConfigureHost(HostBuilderContext hostBuilderContext, IServiceCollection serviceCollection) => serviceCollection.AddHostedService<MySampleBackgroundService>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Protocol" Version="6.5.0" />
<!--ReactiveUI only supports windows 10.0.17763 plus-->
<PackageReference Include="ReactiveUI.WPF" Version="18.4.26" />
<PackageReference Include="Splat.Microsoft.Extensions.DependencyInjection" Version="14.6.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Dapplo.Microsoft.Extensions.Hosting.AppServices\Dapplo.Microsoft.Extensions.Hosting.AppServices.csproj" />
<ProjectReference Include="..\..\src\Dapplo.Microsoft.Extensions.Hosting.Plugins\Dapplo.Microsoft.Extensions.Hosting.Plugins.csproj" />
<ProjectReference Include="..\..\src\Dapplo.Microsoft.Extensions.Hosting.Wpf\Dapplo.Microsoft.Extensions.Hosting.Wpf.csproj" />
<ProjectReference Include="..\..\src\Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf\Dapplo.Microsoft.Extensions.Hosting.ReactiveUI.Wpf.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 9 additions & 7 deletions samples/Dapplo.Hosting.Sample.ReactiveDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<MainWindow>())
.ConfigureLogging()
.ConfigureConfiguration(args)
Expand Down
Loading