Repository: dotnet/aspnetcore
File: src/DefaultBuilder/src/WebHost.cs (C#)

Code before:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HostFiltering;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.StaticWebAssets;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Microsoft.AspNetCore;

/// <summary>
/// Provides convenience methods for creating instances of <see cref="IWebHost"/> and <see cref="IWebHostBuilder"/> with pre-configured defaults.
/// </summary>
[Obsolete("WebHost is obsolete. Use HostBuilder or WebApplicationBuilder instead.", DiagnosticId = "ASPDEPR008")]
public static class WebHost
{
    /// <summary>
    /// Initializes and starts a new <see cref="IWebHost"/> with pre-configured defaults.
    /// See <see cref="CreateDefaultBuilder()"/> for details.
    /// </summary>
    /// <param name="app">A delegate that handles requests to the application.</param>
    /// <returns>A started <see cref="IWebHost"/> that hosts the application.</returns>
    public static IWebHost Start(RequestDelegate app) =>
        Start(url: null!, app: app);

    /// <summary>
    /// Initializes and starts a new <see cref="IWebHost"/> with pre-configured defaults.
    /// See <see cref="CreateDefaultBuilder()"/> for details.
    /// </summary>
    /// <param name="url">The URL the hosted application will listen on.</param>
    /// <param name="app">A delegate that handles requests to the application.</param>
    /// <returns>A started <see cref="IWebHost"/> that hosts the application.</returns>
    public static IWebHost Start([StringSyntax(StringSyntaxAttribute.Uri)] string url, RequestDelegate app)
    {
        var startupAssemblyName = app.GetMethodInfo().DeclaringType!.Assembly.GetName().Name;
        return StartWith(url: url, configureServices: null, app: appBuilder => appBuilder.Run(app), applicationName: startupAssemblyName);
    }

    /// <summary>

Review comment (suggestion):
```suggestion
[Obsolete("WebHost is obsolete. Use HostBuilder or WebApplicationBuilder instead. For more information, visit https://aka.ms/aspnet/deprecate/008.", DiagnosticId = "ASPDEPR008")]
```

Code after:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HostFiltering;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.StaticWebAssets;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Microsoft.AspNetCore;

/// <summary>
/// Provides convenience methods for creating instances of <see cref="IWebHost"/> and <see cref="IWebHostBuilder"/> with pre-configured defaults.
/// </summary>
[Obsolete("WebHost is obsolete. Use HostBuilder or WebApplicationBuilder instead. For more information, visit https://aka.ms/aspnet/deprecate/008.", DiagnosticId = "ASPDEPR008")]
public static class WebHost
{
    /// <summary>
    /// Initializes and starts a new <see cref="IWebHost"/> with pre-configured defaults.
    /// See <see cref="CreateDefaultBuilder()"/> for details.
    /// </summary>
    /// <param name="app">A delegate that handles requests to the application.</param>
    /// <returns>A started <see cref="IWebHost"/> that hosts the application.</returns>
    public static IWebHost Start(RequestDelegate app) =>
        Start(url: null!, app: app);

    /// <summary>
    /// Initializes and starts a new <see cref="IWebHost"/> with pre-configured defaults.
    /// See <see cref="CreateDefaultBuilder()"/> for details.
    /// </summary>
    /// <param name="url">The URL the hosted application will listen on.</param>
    /// <param name="app">A delegate that handles requests to the application.</param>
    /// <returns>A started <see cref="IWebHost"/> that hosts the application.</returns>
    public static IWebHost Start([StringSyntax(StringSyntaxAttribute.Uri)] string url, RequestDelegate app)
    {
        var startupAssemblyName = app.GetMethodInfo().DeclaringType!.Assembly.GetName().Name;
        return StartWith(url: url, configureServices: null, app: appBuilder => appBuilder.Run(app), applicationName: startupAssemblyName);
    }

    /// <summary>