diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ffc06f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +bin/ +obj/ +.idea/ +.vscode/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ diff --git a/Dipper.Alioth/Dipper.Alioth.csproj b/Dipper.Alioth/Dipper.Alioth.csproj new file mode 100644 index 0000000..7a47edc --- /dev/null +++ b/Dipper.Alioth/Dipper.Alioth.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Dipper.Alioth/Info.txt b/Dipper.Alioth/Info.txt new file mode 100644 index 0000000..323289b --- /dev/null +++ b/Dipper.Alioth/Info.txt @@ -0,0 +1,3 @@ +Alioth 玉衡 + +在璿玑玉衡,以齐七政 \ No newline at end of file diff --git a/Dipper.Alioth/Modules/IModule.cs b/Dipper.Alioth/Modules/IModule.cs new file mode 100644 index 0000000..45e099b --- /dev/null +++ b/Dipper.Alioth/Modules/IModule.cs @@ -0,0 +1,6 @@ +namespace Dipper.Alioth; + +public interface IModule +{ + void Initialize(); +} \ No newline at end of file diff --git a/Dipper.Alioth/Options/StarOption.cs b/Dipper.Alioth/Options/StarOption.cs new file mode 100644 index 0000000..86a2a99 --- /dev/null +++ b/Dipper.Alioth/Options/StarOption.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Dipper.Alioth.Options; + +public class StarOption +{ + public IList Modules { get; } + public Action MvcOption { get; set; } + public Action JsonOption { get; set; } + + public StarOption() + { + Modules = new List(); + } +} \ No newline at end of file diff --git a/Dipper.Alioth/Services/IService.cs b/Dipper.Alioth/Services/IService.cs new file mode 100644 index 0000000..73a5b81 --- /dev/null +++ b/Dipper.Alioth/Services/IService.cs @@ -0,0 +1,6 @@ +namespace Dipper.Alioth; + +public interface IService +{ + +} \ No newline at end of file diff --git a/Dipper.Alioth/Web/ServiceConvention.cs b/Dipper.Alioth/Web/ServiceConvention.cs new file mode 100644 index 0000000..42273a7 --- /dev/null +++ b/Dipper.Alioth/Web/ServiceConvention.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc.ApplicationModels; + +namespace Dipper.Alioth.Web; + +public class ServiceConvention : IApplicationModelConvention +{ + public void Apply(ApplicationModel application) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/Dipper.Alioth/Web/ServiceExtension.cs b/Dipper.Alioth/Web/ServiceExtension.cs new file mode 100644 index 0000000..95457b3 --- /dev/null +++ b/Dipper.Alioth/Web/ServiceExtension.cs @@ -0,0 +1,73 @@ +using Dipper.Alioth.Options; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace Dipper.Alioth.Web; + +internal static class ServiceExtension +{ + internal static WebApplicationBuilder AddStarApp(this WebApplicationBuilder builder, Action action) + { + builder.Services.AddSingleton(); + + var option = new StarOption(); + + action?.Invoke(option); + + builder.Services.AddControllers(options => + { + options.EnableEndpointRouting = false; + option.MvcOption?.Invoke(options); + }) + .AddJsonOptions(options => + { + options.JsonSerializerOptions.PropertyNamingPolicy = null; + option.JsonOption?.Invoke(options); + }); + + builder.Services.AddSession(); + + return builder; + } + + internal static WebApplication UserStarApp(this WebApplication app) + { + if (app.Environment.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/?m=Error500"); + } + + app.UseStaticFiles(); + app.UseHttpsRedirection(); + app.UseRouting(); + app.UseSession(); + app.UseAuthorization(); + app.MapControllers(); + + return app; + } + + private static void AddFlexibleApi(IMvcBuilder builder, StarOption option) + { + builder.ConfigureApplicationPartManager(manager => + { + manager.ApplicationParts.Add(new AssemblyPart(typeof(IService).Assembly)); + + foreach (var module in option.Modules) + { + module.Initialize(); + var assembly = module.GetType().Assembly; + manager.ApplicationParts.Add(new AssemblyPart(assembly)); + } + + //manager.FeatureProviders.Add(new ApiFeatureProvider()); + }); + } +} \ No newline at end of file diff --git a/Dipper.Alioth/Web/ServiceFeatureProvider.cs b/Dipper.Alioth/Web/ServiceFeatureProvider.cs new file mode 100644 index 0000000..0646741 --- /dev/null +++ b/Dipper.Alioth/Web/ServiceFeatureProvider.cs @@ -0,0 +1,13 @@ +using System.Reflection; +using Microsoft.AspNetCore.Mvc.Controllers; + +namespace Dipper.Alioth.Web; + +public class ServiceFeatureProvider : ControllerFeatureProvider +{ + protected override bool IsController(TypeInfo typeInfo) + { + return typeof(IService).IsAssignableFrom(typeInfo) && typeInfo.IsPublic + && !typeInfo.IsAbstract && !typeInfo.IsGenericType; + } +} \ No newline at end of file diff --git a/Dipper.Alioth/Web/StarHost.cs b/Dipper.Alioth/Web/StarHost.cs new file mode 100644 index 0000000..8c49395 --- /dev/null +++ b/Dipper.Alioth/Web/StarHost.cs @@ -0,0 +1,31 @@ +using Dipper.Alioth.Options; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; + +namespace Dipper.Alioth.Web; + +public class StarHost +{ + public static void Run(string[] args, Action action) + { + var app = Configure(args, action); + app.Run(); + } + + public static Task RunAsync(string[] args, Action action) + { + var app = Configure(args, action); + + return app.RunAsync(); + } + + + private static WebApplication Configure(string[] args, Action action) + { + var builder = WebApplication.CreateBuilder(args); + + var app = builder.Build(); + + return app; + } +} \ No newline at end of file diff --git a/Dipper.sln b/Dipper.sln new file mode 100644 index 0000000..3683bcb --- /dev/null +++ b/Dipper.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dipper.Alioth", "Dipper.Alioth\Dipper.Alioth.csproj", "{EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal