Skip to content

Document HostingStartup incompatibility and migration to modern hosting patterns for .NET Aspire #4187

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 4, 2025

This PR addresses the incompatibility between HostingStartup and .NET Aspire integrations by providing comprehensive migration guidance from the legacy hosting pattern to the modern IHostApplicationBuilder approach.

The Problem

.NET Aspire integrations require IHostApplicationBuilder, but HostingStartup only provides access to the older IWebHostBuilder. This fundamental API difference means:

  • Aspire integration methods like AddNpgsqlDbContext() are not available
  • Modern hosting features (service discovery, built-in telemetry, health checks) can't be configured
  • Applications using HostingStartup miss out on .NET Aspire's observability and resilience patterns

The Solution

The documentation emphasizes migration as the necessary path forward rather than workarounds, recognizing that HostingStartup represents decade-old technology that predates modern .NET hosting patterns.

Key Content

  • Clear explanation of why the incompatibility exists at the API level
  • Before/after examples showing the transition from IWebHostBuilder to IHostApplicationBuilder
  • Conceptual guidance on the hosting model changes introduced in ASP.NET Core 6.0+
  • Migration resources linking to official ASP.NET Core migration guides and David Fowl's migration patterns

Example Migration

Before (HostingStartup - incompatible):

public class MyDatabaseStartup : IHostingStartup
{
    public void Configure(IWebHostBuilder builder) // ❌ Wrong builder type
    {
        builder.ConfigureServices(services => { ... });
    }
}

After (Modern hosting - compatible):

var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();                    // ✅ Aspire integration
builder.AddNpgsqlDbContext<MyDbContext>("postgres"); // ✅ Works correctly

This approach guides developers toward modern .NET patterns while ensuring they can leverage .NET Aspire's full feature set including service discovery, telemetry, and resilience capabilities.

Fixes #3861.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/fundamentals/integrations-overview.md docs/fundamentals/integrations-overview
docs/toc.yml docs/toc
docs/troubleshooting/hosting-startup-not-supported.md docs/troubleshooting/hosting-startup-not-supported

@Copilot Copilot AI changed the title [WIP] When using Hosting startup I'm unable to configure most if any Aspire services Document HostingStartup incompatibility with .NET Aspire integrations Aug 4, 2025
@Copilot Copilot AI requested a review from IEvangelist August 4, 2025 20:47
Copilot finished work on behalf of IEvangelist August 4, 2025 20:47
…wline, move code snippets to external files, fix ordered list format

Co-authored-by: IEvangelist <[email protected]>
Copilot finished work on behalf of IEvangelist August 6, 2025 21:02
@Copilot Copilot AI requested a review from IEvangelist August 6, 2025 21:02

:::code language="csharp" source="snippets/hosting-startup-not-supported/feature-flags-configuration.cs":::

### Option 4: Use dependency injection for plugin architecture
Copy link
Member

Choose a reason for hiding this comment

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

@copilot - Please remove option 4 and the example source code for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed Option 4 and the dependency injection plugin example code as requested. Fixed in commit 7b9a6ef.

@Copilot Copilot AI requested a review from IEvangelist August 7, 2025 18:32
Copilot finished work on behalf of IEvangelist August 7, 2025 18:32
Copy link
Member

Choose a reason for hiding this comment

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

@copilot - I don't want multiple options listed. Instead, the only option is to migrate. It's time to force their hand so to speak, but really, we're talking about technology that's fast approaching (if not already) over a decade old. When presenting options, push the migration but we don't need to spell it out for them since we already have content for that. Instead, talk through the concepts and the changes to the APIs. Reference things like:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restructured the documentation to focus on migration as the only path forward rather than presenting multiple options. The content now emphasizes the conceptual differences between the older HostingStartup pattern and the modern IHostApplicationBuilder pattern, and references the official ASP.NET Core migration guides and David Fowl's migration resources for detailed guidance. Removed the multiple "options" sections and kept only the essential before/after example to illustrate the API changes. Fixed in commit 329b9fc.

@Copilot Copilot AI changed the title Document HostingStartup incompatibility with .NET Aspire integrations Document HostingStartup incompatibility and migration to modern hosting patterns for .NET Aspire Aug 8, 2025
@Copilot Copilot AI requested a review from IEvangelist August 8, 2025 13:29
Copilot finished work on behalf of IEvangelist August 8, 2025 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When using Hosting startup I'm unable to configure most if any Aspire services
2 participants