新建项目
This commit is contained in:
parent
549244af46
commit
38821ed87a
|
@ -0,0 +1,7 @@
|
|||
bin/
|
||||
obj/
|
||||
.idea/
|
||||
.vscode/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,3 @@
|
|||
Alioth 玉衡
|
||||
|
||||
在璿玑玉衡,以齐七政
|
|
@ -0,0 +1,6 @@
|
|||
namespace Dipper.Alioth;
|
||||
|
||||
public interface IModule
|
||||
{
|
||||
void Initialize();
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dipper.Alioth.Options;
|
||||
|
||||
public class StarOption
|
||||
{
|
||||
public IList<IModule> Modules { get; }
|
||||
public Action<MvcOptions> MvcOption { get; set; }
|
||||
public Action<JsonOptions> JsonOption { get; set; }
|
||||
|
||||
public StarOption()
|
||||
{
|
||||
Modules = new List<IModule>();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace Dipper.Alioth;
|
||||
|
||||
public interface IService
|
||||
{
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<StarOption> action)
|
||||
{
|
||||
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
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());
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<StarOption> action)
|
||||
{
|
||||
var app = Configure(args, action);
|
||||
app.Run();
|
||||
}
|
||||
|
||||
public static Task RunAsync(string[] args, Action<StarOption> action)
|
||||
{
|
||||
var app = Configure(args, action);
|
||||
|
||||
return app.RunAsync();
|
||||
}
|
||||
|
||||
|
||||
private static WebApplication Configure(string[] args, Action<StarOption> action)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue