This commit is contained in:
parent
b6fd17722d
commit
b4e44d388d
|
@ -8,6 +8,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -9,7 +9,7 @@ public static class StartHostExtension
|
|||
/// </summary>
|
||||
/// <param name="host"></param>
|
||||
/// <returns></returns>
|
||||
public static StarHost AddWatchServiceFolder(this StarHost host, string path)
|
||||
public static WebStarHost AddWatchServiceFolder(this WebStarHost host, string path)
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace Dipper.Alioth;
|
||||
|
||||
public interface IModule
|
||||
public interface IStarModule
|
||||
{
|
||||
void Initialize();
|
||||
}
|
|
@ -4,12 +4,12 @@ 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 IList<IStarModule> Modules { get; }
|
||||
public Action<MvcOptions>? MvcOption { get; set; }
|
||||
public Action<JsonOptions>? JsonOption { get; set; }
|
||||
|
||||
public StarOption()
|
||||
{
|
||||
Modules = new List<IModule>();
|
||||
Modules = new List<IStarModule>();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ internal static class ServiceExtension
|
|||
|
||||
action?.Invoke(option);
|
||||
|
||||
builder.Services.AddControllers(options =>
|
||||
var mvcBuilder = builder.Services.AddControllers(options =>
|
||||
{
|
||||
options.EnableEndpointRouting = false;
|
||||
option.MvcOption?.Invoke(options);
|
||||
|
@ -27,6 +27,12 @@ internal static class ServiceExtension
|
|||
options.JsonSerializerOptions.PropertyNamingPolicy = null;
|
||||
option.JsonOption?.Invoke(options);
|
||||
});
|
||||
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
|
||||
});
|
||||
AddFlexibleApi(mvcBuilder, option);
|
||||
|
||||
builder.Services.AddSession();
|
||||
|
||||
|
@ -38,22 +44,30 @@ internal static class ServiceExtension
|
|||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/?m=Error500");
|
||||
}
|
||||
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseRouting();
|
||||
app.UseSession();
|
||||
app.UseAuthorization();
|
||||
app.MapRazorPages();
|
||||
app.MapControllers();
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加动态接口
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <param name="option"></param>
|
||||
private static void AddFlexibleApi(IMvcBuilder builder, StarOption option)
|
||||
{
|
||||
builder.ConfigureApplicationPartManager(manager =>
|
||||
|
|
|
@ -4,25 +4,25 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
|
||||
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);
|
||||
app.Run();
|
||||
}
|
||||
|
||||
public Task RunAsync(string[] args, Action<StarOption> action)
|
||||
public override Task RunAsync(string[] args, Action<StarOption> action)
|
||||
{
|
||||
var app = Configure(args, action);
|
||||
|
||||
|
@ -33,8 +33,10 @@ public class StarHost
|
|||
private WebApplication Configure(string[] args, Action<StarOption> action)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.AddStarApp(action);
|
||||
var app = builder.Build();
|
||||
|
||||
app.UserStarApp();
|
||||
|
||||
return app;
|
||||
}
|
|
@ -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>
|
|
@ -0,0 +1,8 @@
|
|||
using Dipper.Alioth;
|
||||
using Dipper.Alioth.Web;
|
||||
|
||||
WebStarHost.CreateWebHost()
|
||||
.Run(args, options =>
|
||||
{
|
||||
|
||||
});
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
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
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dipper.Demo", "Dipper.Demo\Dipper.Demo.csproj", "{F075C721-EA36-4B54-B90B-0CC4AA1D641C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
EndGlobal
|
||||
|
|
Loading…
Reference in New Issue