-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
199 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<metadata> | ||
<id>ECF.HostedServices</id> | ||
<version>1.0.4</version> | ||
<description>Hosted Services plugin for Easy Console Framewok (ECF).</description> | ||
<authors>Aviuz</authors> | ||
<tags>console IoC ecf</tags> | ||
|
||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<license type="expression">MIT</license> | ||
<copyright>Copyright (c) Aviuz 2023</copyright> | ||
|
||
<language>en-US</language> | ||
<projectUrl>https://github.com/Aviuz/ECF</projectUrl> | ||
<repository type="git" url="https://github.com/Aviuz/ECF.git" /> | ||
<readme>docs\README.md</readme> | ||
|
||
<dependencies> | ||
<group targetFramework="net6"> | ||
<dependency id="EasyConsoleFramework.Base" version="1.0.4" /> | ||
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="6.0.0" /> | ||
</group> | ||
|
||
<group targetFramework="net7"> | ||
<dependency id="EasyConsoleFramework.Base" version="1.0.4" /> | ||
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="7.0.0" /> | ||
</group> | ||
|
||
<group targetFramework="net8"> | ||
<dependency id="EasyConsoleFramework.Base" version="1.0.4" /> | ||
<dependency id="Microsoft.Extensions.Hosting.Abstractions" version="8.0.0" /> | ||
</group> | ||
</dependencies> | ||
</metadata> | ||
|
||
<files> | ||
<file src="..\..\README.md" target="docs\" /> | ||
|
||
<file src="bin\Release\net6.0\ECF.HostedServices.dll" target="lib\net6.0" /> | ||
<file src="bin\Release\net6.0\ECF.HostedServices.pdb" target="lib\net6.0" /> | ||
<file src="bin\Release\net6.0\ECF.HostedServices.deps.json" target="lib\net6.0" /> | ||
|
||
<file src="bin\Release\net7.0\ECF.HostedServices.dll" target="lib\net7.0" /> | ||
<file src="bin\Release\net7.0\ECF.HostedServices.pdb" target="lib\net7.0" /> | ||
<file src="bin\Release\net7.0\ECF.HostedServices.deps.json" target="lib\net7.0" /> | ||
|
||
<file src="bin\Release\net8.0\ECF.HostedServices.dll" target="lib\net8.0" /> | ||
<file src="bin\Release\net8.0\ECF.HostedServices.pdb" target="lib\net8.0" /> | ||
<file src="bin\Release\net8.0\ECF.HostedServices.deps.json" target="lib\net8.0" /> | ||
</files> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Version>1.0.4</Version> | ||
<RootNamespace>ECF.HostedServices</RootNamespace> | ||
<AssemblyName>ECF.HostedServices</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'"> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'"> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'"> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ECF\ECF.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using ECF.Engine; | ||
using ECF.HostedServices; | ||
using ECF.InverseOfControl; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace ECF; | ||
|
||
public static class ECFHostedServicesExtensions | ||
{ | ||
public static ECFHostBuilderBase<TDPBuilderAdapter, TDPBuilder> AddHostedServices<TDPBuilderAdapter, TDPBuilder>(this ECFHostBuilderBase<TDPBuilderAdapter, TDPBuilder> builder) where TDPBuilderAdapter : class, IIoCBuilderAdapter<TDPBuilder> where TDPBuilder : class | ||
{ | ||
HostedServicesRunner runner = new(); | ||
|
||
builder.RegisterStartHandler(runner.StartAsync); | ||
builder.RegisterStopHandler(runner.StopAsync); | ||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using ECF.InverseOfControl; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace ECF.HostedServices; | ||
|
||
internal class HostedServicesRunner | ||
{ | ||
private readonly List<IHostedService> startedServices = new(); | ||
private bool hasStarted = false; | ||
|
||
public async Task StartAsync(IIoCProviderAdapter iocProvider, CancellationToken cancellationToken) | ||
{ | ||
if (hasStarted) | ||
return; | ||
|
||
hasStarted = true; | ||
|
||
foreach (var service in iocProvider.ResolveMultiple<IHostedService>()) | ||
{ | ||
await service.StartAsync(cancellationToken); | ||
startedServices.Add(service); | ||
} | ||
} | ||
|
||
public async Task StopAsync(IIoCProviderAdapter _) | ||
{ | ||
foreach (var service in startedServices) | ||
{ | ||
await service.StopAsync(default); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.