This commit is contained in:
parent
b6fd17722d
commit
b4e44d388d
|
@ -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>
|
||||||
|
|
|
@ -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))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace Dipper.Alioth;
|
namespace Dipper.Alioth;
|
||||||
|
|
||||||
public interface IModule
|
public interface IStarModule
|
||||||
{
|
{
|
||||||
void Initialize();
|
void Initialize();
|
||||||
}
|
}
|
|
@ -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>();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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);
|
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);
|
||||||
|
@ -28,6 +28,12 @@ internal static class ServiceExtension
|
||||||
option.JsonOption?.Invoke(options);
|
option.JsonOption?.Invoke(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.Services.AddSwaggerGen(options =>
|
||||||
|
{
|
||||||
|
|
||||||
|
});
|
||||||
|
AddFlexibleApi(mvcBuilder, option);
|
||||||
|
|
||||||
builder.Services.AddSession();
|
builder.Services.AddSession();
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
|
@ -38,6 +44,8 @@ internal static class ServiceExtension
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -49,11 +57,17 @@ internal static class ServiceExtension
|
||||||
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 =>
|
||||||
|
|
|
@ -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,9 +33,11 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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
|
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
|
||||||
|
|
Loading…
Reference in New Issue