Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net6.0 Minimal API projects without Startup, issue #3794 #3814

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/NSwag.Commands/HostApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ void OnEntryPointExit(Exception exception)
try
{
// Get the IServiceProvider from the host
#if NET6_0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NET6_0_OR_GEATER or else it will be broken in NET 7 again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.
From my understanding, NSwag style has been code tailored to each dotnet version and I made it NET6 specific. DotNet has had many breaking changes in recent versions, so I do hope this works for NET7 as well. :-)

var assemblyName = assembly.GetName()?.FullName ?? string.Empty;
// We should set the application name to the startup assembly to avoid falling back to the entry assembly.
var services = ((IHost)factory(new[] { $"--{HostDefaults.ApplicationKey}={assemblyName}" })).Services;
#else
var services = ((IHost)factory(Array.Empty<string>())).Services;
#endif

// Wait for the application to start so that we know it's fully configured. This is important because
// we need the middleware pipeline to be configured before we access the ISwaggerProvider in
Expand Down Expand Up @@ -176,4 +182,4 @@ public void Dispose() { }
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}
}
}