Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions src/Components/test/testassets/ComponentsApp.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace ComponentsApp.Server;

Expand All @@ -12,10 +13,13 @@ public static void Main(string[] args)
BuildWebHost(args).Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});

public static IWebHost BuildWebHost(string[] args) =>
CreateWebHostBuilder(args).Build();
public static IHost BuildWebHost(string[] args) =>
CreateHostBuilder(args).Build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public async Task WebhostLoadsKeyRingBeforeServerStarts()
new FakeServer(onStart: () => tcs.TrySetException(new InvalidOperationException("Server was started before key ring was initialized")))));
#pragma warning restore ASPDEPR004 // Type or member is obsolete

#pragma warning disable ASPDEPR008 // IWebHost is obsolete
using (var host = builder.Build())
#pragma warning restore ASPDEPR008 // IWebHost is obsolete
{
await host.StartAsync();
}
Expand Down
2 changes: 2 additions & 0 deletions src/DefaultBuilder/samples/SampleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable ASPDEPR008 // Type or member is obsolete

using Microsoft.AspNetCore;

namespace SampleApp;
Expand Down
2 changes: 2 additions & 0 deletions src/DefaultBuilder/src/ConfigureWebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ internal ConfigureWebHostBuilder(WebHostBuilderContext webHostBuilderContext, Co
_context = webHostBuilderContext;
}

#pragma warning disable ASPDEPR008 // IWebHost is obsolete
IWebHost IWebHostBuilder.Build()
{
throw new NotSupportedException($"Call {nameof(WebApplicationBuilder)}.{nameof(WebApplicationBuilder.Build)}() instead.");
}
#pragma warning restore ASPDEPR008 // IWebHost is obsolete

/// <inheritdoc />
public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate)
Expand Down
2 changes: 2 additions & 0 deletions src/DefaultBuilder/src/GenericHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public static IHostBuilder ConfigureWebHostDefaults(this IHostBuilder builder, A

return builder.ConfigureWebHost(webHostBuilder =>
{
#pragma warning disable ASPDEPR008 // Type or member is obsolete
WebHost.ConfigureWebDefaults(webHostBuilder);
#pragma warning restore ASPDEPR008 // Type or member is obsolete

configure(webHostBuilder);
}, configureOptions);
Expand Down
2 changes: 2 additions & 0 deletions src/DefaultBuilder/src/WebApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ internal WebApplicationBuilder(WebApplicationOptions options, bool slim, Action<
bootstrapHostBuilder.ConfigureSlimWebHost(
webHostBuilder =>
{
#pragma warning disable ASPDEPR008 // Type or member is obsolete
AspNetCore.WebHost.ConfigureWebDefaultsSlim(webHostBuilder);
#pragma warning restore ASPDEPR008 // Type or member is obsolete

// Runs inline.
webHostBuilder.Configure(ConfigureApplication);
Expand Down
1 change: 1 addition & 0 deletions src/DefaultBuilder/src/WebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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")]
Copy link
Member

Choose a reason for hiding this comment

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

@BrennanConroy Maybe it's just because it's a TODO that hasn't been actioned yet, but if I visit this link I get this message:

image

public static class WebHost
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable ASPDEPR008 // Type or member is obsolete

using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.IntegrationTesting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ public void WebApplicationBuilderHost_ThrowsWhenBuiltDirectly(CreateBuilderFunc
[MemberData(nameof(CreateBuilderFuncs))]
public void WebApplicationBuilderWebHost_ThrowsWhenBuiltDirectly(CreateBuilderFunc createBuilder)
{
#pragma warning disable ASPDEPR008 // IWebHost is obsolete
Assert.Throws<NotSupportedException>(() => ((IWebHostBuilder)createBuilder().WebHost).Build());
#pragma warning restore ASPDEPR008 // IWebHost is obsolete
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable ASPDEPR008 // IWebHost is obsolete

using System.Collections.Concurrent;
using System.Diagnostics.Tracing;
using Microsoft.AspNetCore.Builder;
Expand Down
38 changes: 21 additions & 17 deletions src/DefaultBuilder/testassets/CreateDefaultBuilderApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace CreateDefaultBuilderApp;

Expand All @@ -16,23 +16,27 @@ static void Main(string[] args)
{
string responseMessage = null;

WebHost.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" })
.ConfigureServices((context, services) => responseMessage = responseMessage ?? GetResponseMessage(context))
.ConfigureKestrel(options => options
.Configure(options.ConfigurationLoader.Configuration)
.Endpoint("HTTP", endpointOptions =>
{
if (responseMessage == null
&& !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"]))
{
responseMessage = "Default Kestrel configuration not read.";
}
}))
.Configure(app => app.Run(context =>
Host.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" })
.ConfigureWebHostDefaults(webBuilder =>
{
var hostingEnvironment = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>();
return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName);
}))
webBuilder
.ConfigureServices((context, services) => responseMessage = responseMessage ?? GetResponseMessage(context))
.ConfigureKestrel(options => options
.Configure(options.ConfigurationLoader.Configuration)
.Endpoint("HTTP", endpointOptions =>
{
if (responseMessage == null
&& !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"]))
{
responseMessage = "Default Kestrel configuration not read.";
}
}))
.Configure(app => app.Run(context =>
{
var hostingEnvironment = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>();
return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName);
}));
})
.Build().Run();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HostFiltering;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -19,31 +18,35 @@ static void Main(string[] args)
{
string responseMessage = null;

WebHost.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" })
.ConfigureServices((context, service) => responseMessage = responseMessage ?? GetResponseMessage(context))
.ConfigureKestrel(options => options
.Configure(options.ConfigurationLoader.Configuration)
.Endpoint("HTTP", endpointOptions =>
{
if (responseMessage == null
&& !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"]))
{
responseMessage = "Default Kestrel configuration not read.";
}
}))
.Configure(app => app.Run(context =>
Host.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" })
.ConfigureWebHostDefaults(webBuilder =>
{
// Verify allowed hosts were loaded
var hostFilteringOptions = app.ApplicationServices.GetRequiredService<IOptions<HostFilteringOptions>>();
var hosts = string.Join(',', hostFilteringOptions.Value.AllowedHosts);
if (responseMessage == null && !string.Equals("example.com,127.0.0.1", hosts, StringComparison.Ordinal))
{
responseMessage = "AllowedHosts not loaded into Options.";
}
webBuilder
.ConfigureServices((context, service) => responseMessage = responseMessage ?? GetResponseMessage(context))
.ConfigureKestrel(options => options
.Configure(options.ConfigurationLoader.Configuration)
.Endpoint("HTTP", endpointOptions =>
{
if (responseMessage == null
&& !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"]))
{
responseMessage = "Default Kestrel configuration not read.";
}
}))
.Configure(app => app.Run(context =>
{
// Verify allowed hosts were loaded
var hostFilteringOptions = app.ApplicationServices.GetRequiredService<IOptions<HostFilteringOptions>>();
var hosts = string.Join(',', hostFilteringOptions.Value.AllowedHosts);
if (responseMessage == null && !string.Equals("example.com,127.0.0.1", hosts, StringComparison.Ordinal))
{
responseMessage = "AllowedHosts not loaded into Options.";
}

var hostingEnvironment = app.ApplicationServices.GetRequiredService<IHostEnvironment>();
return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName);
}))
var hostingEnvironment = app.ApplicationServices.GetRequiredService<IHostEnvironment>();
return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName);
}));
})
.Build()
.Run();
}
Expand Down
44 changes: 24 additions & 20 deletions src/DefaultBuilder/testassets/DependencyInjectionApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace CreateDefaultBuilderApp;

public class Program
{
static void Main(string[] args)
{
WebHost.CreateDefaultBuilder()
.UseUrls("http://127.0.0.1:0")
.ConfigureServices((context, services) =>
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(webBuilder =>
{
services.AddSingleton(typeof(IService<>), typeof(Service<>));
services.AddScoped<IAnotherService, AnotherService>();
})
.Configure(app =>
{
app.Run(context =>
{
try
webBuilder
.UseUrls("http://127.0.0.1:0")
.ConfigureServices((context, services) =>
{
context.RequestServices.GetService<IService<IAnotherService>>();
return context.Response.WriteAsync("Success");
}
catch (Exception ex)
services.AddSingleton(typeof(IService<>), typeof(Service<>));
services.AddScoped<IAnotherService, AnotherService>();
})
.Configure(app =>
{
return context.Response.WriteAsync(ex.ToString());
}
});
app.Run(context =>
{
try
{
context.RequestServices.GetService<IService<IAnotherService>>();
return context.Response.WriteAsync("Success");
}
catch (Exception ex)
{
return context.Response.WriteAsync(ex.ToString());
}
});
});
})
.Build().Run();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable ASPDEPR008 // Type or member is obsolete

using System;
using System.Threading;
using Microsoft.AspNetCore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable ASPDEPR008 // Type or member is obsolete

using System;
using System.Threading;
using Microsoft.AspNetCore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable ASPDEPR008 // Type or member is obsolete

using System;
using System.Threading;
using Microsoft.AspNetCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ public static IWebHostBuilder UseShutdownTimeout(this IWebHostBuilder hostBuilde
/// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to start.</param>
/// <param name="urls">The urls the hosted application will listen on.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
#pragma warning disable ASPDEPR008 // IWebHost is obsolete
public static IWebHost Start(this IWebHostBuilder hostBuilder, [StringSyntax(StringSyntaxAttribute.Uri)] params string[] urls)
{
var host = hostBuilder.UseUrls(urls).Build();
host.StartAsync(CancellationToken.None).GetAwaiter().GetResult();
return host;
}
#pragma warning disable ASPDEPR008 // IWebHost is obsolete
}
1 change: 1 addition & 0 deletions src/Hosting/Abstractions/src/IWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Microsoft.AspNetCore.Hosting;
/// <summary>
/// Represents a configured web host.
/// </summary>
[Obsolete("IWebHost is obsolete. Use IHost instead. For more information, visit https://aka.ms/aspnet/deprecate/008.", DiagnosticId = "ASPDEPR008")]
public interface IWebHost : IDisposable
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Hosting/Abstractions/src/IWebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface IWebHostBuilder
/// <summary>
/// Builds an <see cref="IWebHost"/> which hosts a web application.
/// </summary>
[Obsolete("IWebHost is obsolete. Use IHost instead. For more information, visit https://aka.ms/aspnet/deprecate/008.", DiagnosticId = "ASPDEPR008")]
IWebHost Build();

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public HostingStartupWebHostBuilder(GenericWebHostBuilder builder)
_builder = builder;
}

#pragma warning disable ASPDEPR008 // IWebHost is obsolete
public IWebHost Build()
{
throw new NotSupportedException($"Building this implementation of {nameof(IWebHostBuilder)} is not supported.");
}
#pragma warning restore ASPDEPR008 // IWebHost is obsolete

public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Hosting/Hosting/src/GenericHost/WebHostBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public WebHostBuilderBase(IHostBuilder builder, WebHostBuilderOptions options)
_config = configBuilder.Build();
}

#pragma warning disable ASPDEPR008 // IWebHost is obsolete
public IWebHost Build()
{
throw new NotSupportedException($"Building this implementation of {nameof(IWebHostBuilder)} is not supported.");
}
#pragma warning restore ASPDEPR008 // IWebHost is obsolete

public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate)
{
Expand Down
1 change: 1 addition & 0 deletions src/Hosting/Hosting/src/Internal/WebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Microsoft.AspNetCore.Hosting;

[Obsolete("WebHost is obsolete. Use Host.CreateDefaultBuilder or WebApplication.CreateBuilder instead.")]
internal sealed partial class WebHost : IWebHost, IAsyncDisposable
{
private const string DeprecatedServerUrlsKey = "server.urls";
Expand Down
Loading
Loading