dotnet-getdocument issues in .NET7
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
We're currently on .NET6 and trying to migrate to .NET7. We're making use of `` and ``. The implementation of `GetDocument.Insider` has changed in .NET7 ([https://github.com/dotnet/aspnetcore/pull/43701](https://github.com/dotnet/aspnetcore/pull/43701)) to start all `IHostedService` implementations and allow for all DI configuration to be executed. As pointed out by [bachratyg](https://github.com/dotnet/aspnetcore/issues/43391#issuecomment-1220878694) this implementation might be handy for some cases, but is also completely undesirable for others. For example, we're using a `IHostedService` implementation to make a call to a microservice in the same solution at startup, which is now impossible to do. We're also validating the presence of certain configuration entries at startup e.g:
` if (string.IsNullOrEmpty(config.GetConnectionString("database"))) { throw new Exception(); }`. This now fails because these are defined in our docker-compose.yml file.
I'm not sure if there's a one-size-fits-all solution to this problem but it would at least be nice to have the option to revert back to the previous behaviour.
### Expected Behavior
The project builds succesfully and generates an openapi document without invoking a bunch of application code.
### Steps To Reproduce
A .csproj:
```xml
net7.0
true
enable
```
Example scenarios:
- Register an `IHostedService` implementation that executes some logic which is impossible to do at build time. For example making a call to a microservice in the same solution.
- Validate the presence of a configuration entry which is defined outside of `appsettings.json` (e.g. user secrets or docker-compose.yml). For example:
```CSharp
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("Database");
if (string.IsNullOrEmpty(connectionString))
{
throw new Exception();
}
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
```
The project now fails to build.
### Exceptions (if any)
_No response_
### .NET Version
7
### Anything else?
Related:
- [https://github.com/dotnet/aspnetcore/issues/43391](https://github.com/dotnet/aspnetcore/issues/43391)
- [https://github.com/dotnet/aspnetcore/pull/43701](https://github.com/dotnet/aspnetcore/pull/43701)
Contributor guide
Assessment
This issue has not been assessed yet.