This commit is contained in:
Sanchime 2022-11-09 22:06:06 +08:00
parent b6fd17722d
commit b4e44d388d
13 changed files with 116 additions and 15 deletions

View File

@ -8,6 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" /> <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -9,7 +9,7 @@ public static class StartHostExtension
/// </summary> /// </summary>
/// <param name="host"></param> /// <param name="host"></param>
/// <returns></returns> /// <returns></returns>
public static StarHost AddWatchServiceFolder(this StarHost host, string path) public static WebStarHost AddWatchServiceFolder(this WebStarHost host, string path)
{ {
if (!Directory.Exists(path)) if (!Directory.Exists(path))
{ {

View File

@ -1,6 +1,6 @@
namespace Dipper.Alioth; namespace Dipper.Alioth;
public interface IModule public interface IStarModule
{ {
void Initialize(); void Initialize();
} }

View File

@ -4,12 +4,12 @@ namespace Dipper.Alioth.Options;
public class StarOption public class StarOption
{ {
public IList<IModule> Modules { get; } public IList<IStarModule> Modules { get; }
public Action<MvcOptions> MvcOption { get; set; } public Action<MvcOptions>? MvcOption { get; set; }
public Action<JsonOptions> JsonOption { get; set; } public Action<JsonOptions>? JsonOption { get; set; }
public StarOption() public StarOption()
{ {
Modules = new List<IModule>(); Modules = new List<IStarModule>();
} }
} }

12
Dipper.Alioth/StarHost.cs Normal file
View File

@ -0,0 +1,12 @@
using Dipper.Alioth.Options;
namespace Dipper.Alioth;
public abstract class StarHost
{
public abstract void Run(string[] args, Action<StarOption> action);
public abstract Task RunAsync(string[] args, Action<StarOption> action);
}

View File

@ -17,7 +17,7 @@ internal static class ServiceExtension
action?.Invoke(option); action?.Invoke(option);
builder.Services.AddControllers(options => var mvcBuilder = builder.Services.AddControllers(options =>
{ {
options.EnableEndpointRouting = false; options.EnableEndpointRouting = false;
option.MvcOption?.Invoke(options); option.MvcOption?.Invoke(options);
@ -27,6 +27,12 @@ internal static class ServiceExtension
options.JsonSerializerOptions.PropertyNamingPolicy = null; options.JsonSerializerOptions.PropertyNamingPolicy = null;
option.JsonOption?.Invoke(options); option.JsonOption?.Invoke(options);
}); });
builder.Services.AddSwaggerGen(options =>
{
});
AddFlexibleApi(mvcBuilder, option);
builder.Services.AddSession(); builder.Services.AddSession();
@ -38,22 +44,30 @@ internal static class ServiceExtension
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI();
} }
else else
{ {
app.UseExceptionHandler("/?m=Error500"); app.UseExceptionHandler("/?m=Error500");
} }
app.UseStaticFiles(); app.UseStaticFiles();
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseRouting(); app.UseRouting();
app.UseSession(); app.UseSession();
app.UseAuthorization(); app.UseAuthorization();
app.MapRazorPages();
app.MapControllers(); app.MapControllers();
return app; return app;
} }
/// <summary>
/// 添加动态接口
/// </summary>
/// <param name="builder"></param>
/// <param name="option"></param>
private static void AddFlexibleApi(IMvcBuilder builder, StarOption option) private static void AddFlexibleApi(IMvcBuilder builder, StarOption option)
{ {
builder.ConfigureApplicationPartManager(manager => builder.ConfigureApplicationPartManager(manager =>

View File

@ -4,25 +4,25 @@ using Microsoft.Extensions.DependencyInjection;
namespace Dipper.Alioth.Web; namespace Dipper.Alioth.Web;
public class StarHost public class WebStarHost : StarHost
{ {
private StarHost() private WebStarHost()
{ {
} }
public StarHost CreateHost() public static WebStarHost CreateWebHost()
{ {
return new StarHost(); return new WebStarHost();
} }
public void Run(string[] args, Action<StarOption> action) public override void Run(string[] args, Action<StarOption> action)
{ {
var app = Configure(args, action); var app = Configure(args, action);
app.Run(); app.Run();
} }
public Task RunAsync(string[] args, Action<StarOption> action) public override Task RunAsync(string[] args, Action<StarOption> action)
{ {
var app = Configure(args, action); var app = Configure(args, action);
@ -33,8 +33,10 @@ public class StarHost
private WebApplication Configure(string[] args, Action<StarOption> action) private WebApplication Configure(string[] args, Action<StarOption> action)
{ {
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.AddStarApp(action);
var app = builder.Build(); var app = builder.Build();
app.UserStarApp();
return app; return app;
} }

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dipper.Alioth\Dipper.Alioth.csproj" />
</ItemGroup>
</Project>

8
Dipper.Demo/Program.cs Normal file
View File

@ -0,0 +1,8 @@
using Dipper.Alioth;
using Dipper.Alioth.Web;
WebStarHost.CreateWebHost()
.Run(args, options =>
{
});

View File

@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:42985",
"sslPort": 44395
}
},
"profiles": {
"Dipper.Demo": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7064;http://localhost:5038",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dipper.Alioth", "Dipper.Alioth\Dipper.Alioth.csproj", "{EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dipper.Demo", "Dipper.Demo\Dipper.Demo.csproj", "{F075C721-EA36-4B54-B90B-0CC4AA1D641C}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -12,5 +14,9 @@ Global
{EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}.Release|Any CPU.Build.0 = Release|Any CPU {EF5E7BBF-F064-49A9-A191-EE67DA70CC8E}.Release|Any CPU.Build.0 = Release|Any CPU
{F075C721-EA36-4B54-B90B-0CC4AA1D641C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F075C721-EA36-4B54-B90B-0CC4AA1D641C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F075C721-EA36-4B54-B90B-0CC4AA1D641C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F075C721-EA36-4B54-B90B-0CC4AA1D641C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal