Skip to content

Commit e71e04b

Browse files
committed
Dealing w/ Eager setting in HTTP + the codegen command. Closes GH-1567
1 parent 3f25212 commit e71e04b

File tree

188 files changed

+9785
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+9785
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5"/>
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\Wolverine.Http\Wolverine.Http.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@CodeGenTarget_HostAddress = http://localhost:5224
2+
3+
GET {{CodeGenTarget_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// <auto-generated/>
2+
#pragma warning disable
3+
using Microsoft.AspNetCore.Routing;
4+
using System;
5+
using System.Linq;
6+
using Wolverine.Http;
7+
8+
namespace Internal.Generated.WolverineHandlers
9+
{
10+
// START: GET_api_test
11+
[global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")]
12+
public sealed class GET_api_test : Wolverine.Http.HttpHandler
13+
{
14+
private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions;
15+
16+
public GET_api_test(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions) : base(wolverineHttpOptions)
17+
{
18+
_wolverineHttpOptions = wolverineHttpOptions;
19+
}
20+
21+
22+
23+
public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext)
24+
{
25+
26+
// The actual HTTP request handler execution
27+
var result_of_Handle = ExampleHandler.Handle();
28+
29+
await WriteString(httpContext, result_of_Handle);
30+
}
31+
32+
}
33+
34+
// END: GET_api_test
35+
36+
37+
}
38+

src/Http/CodeGenTarget/Program.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using JasperFx;
2+
using Wolverine;
3+
using Wolverine.Http;
4+
5+
var builder = WebApplication.CreateBuilder(args);
6+
7+
// Add services to the container.
8+
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
9+
builder.Services.AddOpenApi();
10+
11+
builder.Host.UseWolverine();
12+
builder.Services.AddWolverineHttp();
13+
14+
var app = builder.Build();
15+
16+
// Configure the HTTP request pipeline.
17+
if (app.Environment.IsDevelopment())
18+
{
19+
app.MapOpenApi();
20+
}
21+
22+
app.MapWolverineEndpoints(x => x.WarmUpRoutes = RouteWarmup.Eager);
23+
24+
return await app.RunJasperFxCommands(args);
25+
26+
public static class ExampleHandler
27+
{
28+
[WolverineGet("/api/test")]
29+
public static string Handle()
30+
{
31+
return "tested";
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": false,
8+
"applicationUrl": "http://localhost:5224",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
},
13+
"https": {
14+
"commandName": "Project",
15+
"dotnetRunMessages": true,
16+
"launchBrowser": false,
17+
"applicationUrl": "https://localhost:7246;http://localhost:5224",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
}
22+
}
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}

src/Http/Wolverine.Http/HttpChain.Codegen.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public partial class HttpChain
3232

3333
void ICodeFile.AssembleTypes(GeneratedAssembly assembly)
3434
{
35-
if (_generatedType != null) return;
35+
if (_generatedType != null)
36+
{
37+
return;
38+
}
3639

3740
lock (_locker)
3841
{

src/Http/Wolverine.Http/HttpChain.EndpointBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public RouteEndpoint BuildEndpoint(RouteWarmup warmup)
6161
}
6262
else
6363
{
64-
if (warmup == RouteWarmup.Eager)
64+
if (warmup == RouteWarmup.Eager && !DynamicCodeBuilder.WithinCodegenCommand)
6565
{
6666
this.InitializeSynchronously(_parent.Rules, _parent, _parent.Container.Services);
6767
var handler = (HttpHandler)_parent.Container.QuickBuild(_handlerType);

src/Http/Wolverine.Http/WolverineHttpEndpointRouteBuilderExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ public static void MapWolverineEndpoints(this IEndpointRouteBuilder endpoints,
191191
options.Endpoints = new HttpGraph(runtime.Options, serviceProvider.GetRequiredService<IServiceContainer>());
192192

193193
configure?.Invoke(options);
194+
195+
if (Environment.CommandLine.Contains("codegen", StringComparison.OrdinalIgnoreCase))
196+
{
197+
options.WarmUpRoutes = RouteWarmup.Lazy;
198+
}
194199

195200
options.JsonSerializerOptions = new Lazy<JsonSerializerOptions>(() => serviceProvider.GetService<IOptions<JsonOptions>>()?.Value?.SerializerOptions ?? new JsonSerializerOptions());
196201

0 commit comments

Comments
 (0)