-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from hadashiA/ku/dotnet
Add VitalRouter.Extensions.Hosting
- Loading branch information
Showing
306 changed files
with
625 additions
and
140 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
Binary file removed
BIN
-73.5 KB
VitalRouter.Unity/Assets/VitalRouter/Runtime/VitalRouter.SourceGenerator.dll
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,28 +1,51 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VitalRouter.SourceGenerator", "VitalRouter.SourceGenerator\VitalRouter.SourceGenerator.csproj", "{1E429509-F841-48F1-A111-5D0CD35707CC}" | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VitalRouter", "src\VitalRouter\VitalRouter.csproj", "{5EB8B2E1-8C01-4D6F-96B3-F4DC0E8BE4C6}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VitalRouter", "VitalRouter\VitalRouter.csproj", "{DD9A5ED8-8B7E-4F41-BDB6-67294C5752D9}" | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VitalRouter.SourceGenerator", "src\VitalRouter.SourceGenerator\VitalRouter.SourceGenerator.csproj", "{40D96280-07A3-408E-AB76-642FEE5E0EAE}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VitalRouter.Tests", "VitalRouter.Tests\VitalRouter.Tests.csproj", "{A7FF360B-BC95-4EDD-8905-6B39592840B3}" | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VitalRouter.Extensions.Hosting", "src\VitalRouter.Extensions.Hosting\VitalRouter.Extensions.Hosting.csproj", "{4ECC08A7-9829-47DB-AA97-88CEE6743838}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VitalRouter.Tests", "tests\VitalRouter.Tests\VitalRouter.Tests.csproj", "{163E0808-D858-4C31-9C37-A0B50B912608}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VitalRouter.Extensions.Hosting.Tests", "tests\VitalRouter.Extensions.Hosting.Tests\VitalRouter.Extensions.Hosting.Tests.csproj", "{E6C26E17-4F85-48C8-B5C9-1DC1549C362D}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{40063808-A412-46A8-A4E2-E77256444895}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CBCBF5DB-09AA-4FAD-A9D1-C148885BB189}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1E429509-F841-48F1-A111-5D0CD35707CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1E429509-F841-48F1-A111-5D0CD35707CC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1E429509-F841-48F1-A111-5D0CD35707CC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1E429509-F841-48F1-A111-5D0CD35707CC}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{DD9A5ED8-8B7E-4F41-BDB6-67294C5752D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DD9A5ED8-8B7E-4F41-BDB6-67294C5752D9}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DD9A5ED8-8B7E-4F41-BDB6-67294C5752D9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DD9A5ED8-8B7E-4F41-BDB6-67294C5752D9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A7FF360B-BC95-4EDD-8905-6B39592840B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A7FF360B-BC95-4EDD-8905-6B39592840B3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A7FF360B-BC95-4EDD-8905-6B39592840B3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A7FF360B-BC95-4EDD-8905-6B39592840B3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{5EB8B2E1-8C01-4D6F-96B3-F4DC0E8BE4C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5EB8B2E1-8C01-4D6F-96B3-F4DC0E8BE4C6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5EB8B2E1-8C01-4D6F-96B3-F4DC0E8BE4C6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5EB8B2E1-8C01-4D6F-96B3-F4DC0E8BE4C6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{40D96280-07A3-408E-AB76-642FEE5E0EAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{40D96280-07A3-408E-AB76-642FEE5E0EAE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{40D96280-07A3-408E-AB76-642FEE5E0EAE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{40D96280-07A3-408E-AB76-642FEE5E0EAE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{4ECC08A7-9829-47DB-AA97-88CEE6743838}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4ECC08A7-9829-47DB-AA97-88CEE6743838}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4ECC08A7-9829-47DB-AA97-88CEE6743838}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4ECC08A7-9829-47DB-AA97-88CEE6743838}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{163E0808-D858-4C31-9C37-A0B50B912608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{163E0808-D858-4C31-9C37-A0B50B912608}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{163E0808-D858-4C31-9C37-A0B50B912608}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{163E0808-D858-4C31-9C37-A0B50B912608}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E6C26E17-4F85-48C8-B5C9-1DC1549C362D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E6C26E17-4F85-48C8-B5C9-1DC1549C362D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E6C26E17-4F85-48C8-B5C9-1DC1549C362D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E6C26E17-4F85-48C8-B5C9-1DC1549C362D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{5EB8B2E1-8C01-4D6F-96B3-F4DC0E8BE4C6} = {40063808-A412-46A8-A4E2-E77256444895} | ||
{4ECC08A7-9829-47DB-AA97-88CEE6743838} = {40063808-A412-46A8-A4E2-E77256444895} | ||
{40D96280-07A3-408E-AB76-642FEE5E0EAE} = {40063808-A412-46A8-A4E2-E77256444895} | ||
{E6C26E17-4F85-48C8-B5C9-1DC1549C362D} = {CBCBF5DB-09AA-4FAD-A9D1-C148885BB189} | ||
{163E0808-D858-4C31-9C37-A0B50B912608} = {CBCBF5DB-09AA-4FAD-A9D1-C148885BB189} | ||
EndGlobalSection | ||
EndGlobal |
This file was deleted.
Oops, something went wrong.
130 changes: 130 additions & 0 deletions
130
src/VitalRouter.Extensions.Hosting/ServiceCollectionExtensions.cs
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,130 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using VitalRouter.Internal; | ||
|
||
namespace VitalRouter; | ||
|
||
public class VitalRouterOptions | ||
{ | ||
public InterceptorStackBuilder Filters { get; } = new(); | ||
public CommandOrdering Ordering { get; set; } | ||
|
||
internal readonly List<MapRoutesInfo> MapRoutesInfos = []; | ||
internal readonly List<VitalRouterOptions> Subsequents = []; | ||
|
||
public VitalRouterOptions MapAll(Assembly assembly) | ||
{ | ||
var types = assembly.GetTypes().Where(x => x.GetCustomAttribute<RoutesAttribute>() != null); | ||
foreach (var type in types) | ||
{ | ||
MapRoutesInfos.Add(MapRoutesInfo.Analyze(type)); | ||
} | ||
return this; | ||
} | ||
|
||
public VitalRouterOptions Map<T>() | ||
{ | ||
MapRoutesInfos.Add(MapRoutesInfo.Analyze(typeof(T))); | ||
return this; | ||
} | ||
|
||
public VitalRouterOptions Map<T>(T instance) where T : class | ||
{ | ||
MapRoutesInfos.Add(MapRoutesInfo.Analyze(typeof(T))); | ||
return this; | ||
} | ||
|
||
public VitalRouterOptions Sequential() | ||
{ | ||
Filters.Add<SequentialOrdering>(); | ||
return this; | ||
} | ||
|
||
public VitalRouterOptions FanOut(Action<VitalRouterOptions> configure) | ||
{ | ||
var subsequent = new VitalRouterOptions(); | ||
configure(subsequent); | ||
Subsequents.Add(subsequent); | ||
return this; | ||
} | ||
} | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddVitalRouter(this IServiceCollection services) | ||
{ | ||
return services.AddVitalRouter(static _ => { }); | ||
} | ||
|
||
public static IServiceCollection AddVitalRouter(this IServiceCollection services, Action<VitalRouterOptions> configure) | ||
{ | ||
var options = new VitalRouterOptions(); | ||
configure(options); | ||
|
||
var router = new Router(); | ||
services.AddSingleton(router); | ||
var routers = new List<(Router, VitalRouterOptions)>(); | ||
services.AddVitalRouterRecursive(router, options, routers); | ||
services.AddHostedService(container => new VitalRouterHostedService(container, routers)); | ||
|
||
return services; | ||
} | ||
|
||
static IServiceCollection AddVitalRouterInterceptors(this IServiceCollection services, VitalRouterOptions options) | ||
{ | ||
switch (options.Ordering) | ||
{ | ||
case CommandOrdering.Sequential: | ||
options.Filters.Add<SequentialOrdering>(); | ||
break; | ||
} | ||
|
||
foreach (var interceptorType in options.Filters.Types) | ||
{ | ||
services.TryAddSingleton(interceptorType); | ||
} | ||
|
||
foreach (var info in options.MapRoutesInfos) | ||
{ | ||
for (var paramIndex = 1; paramIndex < info.ParameterInfos.Length; paramIndex++) | ||
{ | ||
var interceptorType = info.ParameterInfos[paramIndex].ParameterType; | ||
services.TryAddSingleton(interceptorType); | ||
} | ||
} | ||
|
||
return services; | ||
} | ||
|
||
static void AddVitalRouterRecursive( | ||
this IServiceCollection services, | ||
Router routerInstance, | ||
VitalRouterOptions options, | ||
ICollection<(Router, VitalRouterOptions)> routers) | ||
{ | ||
services.AddVitalRouterInterceptors(options); | ||
|
||
foreach (var info in options.MapRoutesInfos) | ||
{ | ||
services.TryAddSingleton(info.Type); | ||
} | ||
|
||
if (options.Subsequents.Count > 0) | ||
{ | ||
var fanOut = new FanOutInterceptor(); | ||
foreach (var subsequentOptions in options.Subsequents) | ||
{ | ||
var subsequentRouter = new Router(); | ||
services.AddVitalRouterRecursive(subsequentRouter, subsequentOptions, routers); | ||
fanOut.Add(subsequentRouter); | ||
} | ||
routerInstance.Filter(fanOut); | ||
} | ||
|
||
routers.Add((routerInstance, options)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/VitalRouter.Extensions.Hosting/VitalRouter.Extensions.Hosting.csproj
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks> | ||
<LangVersion>12</LangVersion> | ||
<ImplicitUsings>disable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\VitalRouter\VitalRouter.csproj" /> | ||
<ProjectReference Include="..\VitalRouter.SourceGenerator\VitalRouter.SourceGenerator.csproj"> | ||
<OutputItemType>Analyzer</OutputItemType> | ||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly> | ||
</ProjectReference> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.