From 6c23330c62f1f811305a5ae2a79deab4a04852a4 Mon Sep 17 00:00:00 2001 From: Sanchime Date: Sun, 27 Nov 2022 18:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E7=A7=BB=E9=99=A4part?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{Web => Extensions}/StarletExtension.cs | 14 ++-------- .../Extensions/StartHostExtension.cs | 2 -- Dipper.Alioth/GlobalUsings.cs | 11 ++++++++ Dipper.Alioth/ManagerStarlet.cs | 20 ------------- Dipper.Alioth/Options/StarOption.cs | 3 -- ...eProvider.cs => StarletFeatureProvider.cs} | 3 +- .../{ => Services}/DomainAsterism.cs | 4 +-- Dipper.Alioth/Services/ManagerStarlet.cs | 28 +++++++++++++++++++ Dipper.Alioth/StarHost.cs | 4 --- Dipper.Alioth/Web/StarletConvention.cs | 2 -- Dipper.Alioth/Web/StarletFeatureProvider.cs | 14 ---------- Dipper.Alioth/Web/WebStarHost.cs | 4 +-- Dipper.Demo/Program.cs | 2 ++ 13 files changed, 46 insertions(+), 65 deletions(-) rename Dipper.Alioth/{Web => Extensions}/StarletExtension.cs (80%) create mode 100644 Dipper.Alioth/GlobalUsings.cs delete mode 100644 Dipper.Alioth/ManagerStarlet.cs rename Dipper.Alioth/Providers/{ApiFeatureProvider.cs => StarletFeatureProvider.cs} (81%) rename Dipper.Alioth/{ => Services}/DomainAsterism.cs (69%) create mode 100644 Dipper.Alioth/Services/ManagerStarlet.cs delete mode 100644 Dipper.Alioth/Web/StarletFeatureProvider.cs diff --git a/Dipper.Alioth/Web/StarletExtension.cs b/Dipper.Alioth/Extensions/StarletExtension.cs similarity index 80% rename from Dipper.Alioth/Web/StarletExtension.cs rename to Dipper.Alioth/Extensions/StarletExtension.cs index f28bd87..add64e3 100644 --- a/Dipper.Alioth/Web/StarletExtension.cs +++ b/Dipper.Alioth/Extensions/StarletExtension.cs @@ -1,14 +1,4 @@ -using Dipper.Alioth.Options; -using Dipper.Alioth.Providers; -using Dipper.Alioth.Starlets; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace Dipper.Alioth.Web; +namespace Dipper.Alioth.Extensions; public static class StarletExtension { @@ -64,7 +54,7 @@ public static class StarletExtension manager.ApplicationParts.Add(new AssemblyPart(assembly)); } - manager.FeatureProviders.Add(new ApiFeatureProvider()); + manager.FeatureProviders.Add(new Providers.StarletFeatureProvider()); }); builder.Services.Configure(options => diff --git a/Dipper.Alioth/Extensions/StartHostExtension.cs b/Dipper.Alioth/Extensions/StartHostExtension.cs index 796ef3c..c5a6527 100644 --- a/Dipper.Alioth/Extensions/StartHostExtension.cs +++ b/Dipper.Alioth/Extensions/StartHostExtension.cs @@ -1,5 +1,3 @@ -using Dipper.Alioth.Web; - namespace Dipper.Alioth.Extensions; public static class StartHostExtension diff --git a/Dipper.Alioth/GlobalUsings.cs b/Dipper.Alioth/GlobalUsings.cs new file mode 100644 index 0000000..8ce4673 --- /dev/null +++ b/Dipper.Alioth/GlobalUsings.cs @@ -0,0 +1,11 @@ +global using Dipper.Alioth.Options; +global using Dipper.Alioth.Providers; +global using Dipper.Alioth.Starlets; +global using Dipper.Alioth.Web; +global using Dipper.Alioth.Extensions; +global using Microsoft.AspNetCore.Builder; +global using Microsoft.AspNetCore.Http; +global using Microsoft.AspNetCore.Mvc; +global using Microsoft.AspNetCore.Mvc.ApplicationParts; +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Hosting; \ No newline at end of file diff --git a/Dipper.Alioth/ManagerStarlet.cs b/Dipper.Alioth/ManagerStarlet.cs deleted file mode 100644 index 6e4dac8..0000000 --- a/Dipper.Alioth/ManagerStarlet.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Dipper.Alioth.Starlets; -using Microsoft.AspNetCore.Mvc.ApplicationParts; - -namespace Dipper.Alioth; - -public class ManagerStarlet : IStarlet -{ - private ApplicationPartManager _partManager; - - - public ManagerStarlet(ApplicationPartManager partManager) - { - _partManager = partManager; - } - - public IEnumerable GetList() - { - return _partManager.ApplicationParts.Select(x => x.Name); - } -} \ No newline at end of file diff --git a/Dipper.Alioth/Options/StarOption.cs b/Dipper.Alioth/Options/StarOption.cs index 6d596ca..831f550 100644 --- a/Dipper.Alioth/Options/StarOption.cs +++ b/Dipper.Alioth/Options/StarOption.cs @@ -1,6 +1,3 @@ -using Dipper.Alioth.Starlets; -using Microsoft.AspNetCore.Mvc; - namespace Dipper.Alioth.Options; public class StarOption diff --git a/Dipper.Alioth/Providers/ApiFeatureProvider.cs b/Dipper.Alioth/Providers/StarletFeatureProvider.cs similarity index 81% rename from Dipper.Alioth/Providers/ApiFeatureProvider.cs rename to Dipper.Alioth/Providers/StarletFeatureProvider.cs index d7d896a..4903933 100644 --- a/Dipper.Alioth/Providers/ApiFeatureProvider.cs +++ b/Dipper.Alioth/Providers/StarletFeatureProvider.cs @@ -1,10 +1,9 @@ using System.Reflection; -using Dipper.Alioth.Starlets; using Microsoft.AspNetCore.Mvc.Controllers; namespace Dipper.Alioth.Providers; -public class ApiFeatureProvider : ControllerFeatureProvider +public class StarletFeatureProvider : ControllerFeatureProvider { protected override bool IsController(TypeInfo typeInfo) { diff --git a/Dipper.Alioth/DomainAsterism.cs b/Dipper.Alioth/Services/DomainAsterism.cs similarity index 69% rename from Dipper.Alioth/DomainAsterism.cs rename to Dipper.Alioth/Services/DomainAsterism.cs index 4fca798..7c1f5e7 100644 --- a/Dipper.Alioth/DomainAsterism.cs +++ b/Dipper.Alioth/Services/DomainAsterism.cs @@ -1,6 +1,4 @@ -using Dipper.Alioth.Starlets; - -namespace Dipper.Alioth; +namespace Dipper.Alioth.Services; public class DomainAsterism : IAsterism { diff --git a/Dipper.Alioth/Services/ManagerStarlet.cs b/Dipper.Alioth/Services/ManagerStarlet.cs new file mode 100644 index 0000000..37adec0 --- /dev/null +++ b/Dipper.Alioth/Services/ManagerStarlet.cs @@ -0,0 +1,28 @@ +namespace Dipper.Alioth.Services; + +public class ManagerStarlet : IStarlet +{ + private readonly ApplicationPartManager _partManager; + + + public ManagerStarlet(ApplicationPartManager partManager) + { + _partManager = partManager; + } + + public IEnumerable GetList() + { + return _partManager.ApplicationParts.Select(x => x.Name); + } + + public bool Remove(string name) + { + var part = _partManager.ApplicationParts.FirstOrDefault(part => part.Name == name); + if (part is null) + { + return false; + } + + return _partManager.ApplicationParts.Remove(part); + } +} \ No newline at end of file diff --git a/Dipper.Alioth/StarHost.cs b/Dipper.Alioth/StarHost.cs index aeb9976..c3d53e7 100644 --- a/Dipper.Alioth/StarHost.cs +++ b/Dipper.Alioth/StarHost.cs @@ -1,5 +1,3 @@ -using Dipper.Alioth.Options; - namespace Dipper.Alioth; public abstract class StarHost @@ -7,6 +5,4 @@ public abstract class StarHost public abstract void Run(string[] args, Action action); public abstract Task RunAsync(string[] args, Action action); - - } \ No newline at end of file diff --git a/Dipper.Alioth/Web/StarletConvention.cs b/Dipper.Alioth/Web/StarletConvention.cs index 0a36dbb..4caf359 100644 --- a/Dipper.Alioth/Web/StarletConvention.cs +++ b/Dipper.Alioth/Web/StarletConvention.cs @@ -1,6 +1,4 @@ using System.Text; -using Dipper.Alioth.Starlets; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.ApplicationModels; diff --git a/Dipper.Alioth/Web/StarletFeatureProvider.cs b/Dipper.Alioth/Web/StarletFeatureProvider.cs deleted file mode 100644 index c04efd9..0000000 --- a/Dipper.Alioth/Web/StarletFeatureProvider.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Reflection; -using Dipper.Alioth.Starlets; -using Microsoft.AspNetCore.Mvc.Controllers; - -namespace Dipper.Alioth.Web; - -public class StarletFeatureProvider : ControllerFeatureProvider -{ - protected override bool IsController(TypeInfo typeInfo) - { - return typeof(IStarlet).IsAssignableFrom(typeInfo) && typeInfo.IsPublic - && !typeInfo.IsAbstract && !typeInfo.IsGenericType; - } -} \ No newline at end of file diff --git a/Dipper.Alioth/Web/WebStarHost.cs b/Dipper.Alioth/Web/WebStarHost.cs index 798cf73..a330099 100644 --- a/Dipper.Alioth/Web/WebStarHost.cs +++ b/Dipper.Alioth/Web/WebStarHost.cs @@ -1,6 +1,4 @@ -using Dipper.Alioth.Options; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; + namespace Dipper.Alioth.Web; diff --git a/Dipper.Demo/Program.cs b/Dipper.Demo/Program.cs index ec56226..ad0560a 100644 --- a/Dipper.Demo/Program.cs +++ b/Dipper.Demo/Program.cs @@ -1,4 +1,6 @@ using Dipper.Alioth; +using Dipper.Alioth.Extensions; +using Dipper.Alioth.Services; using Dipper.Alioth.Web; var builder = WebApplication.CreateBuilder(args);