Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Renaming WebApplication* to WebHost* #577

Merged
merged 1 commit into from
Jan 17, 2016
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
10 changes: 4 additions & 6 deletions samples/SampleStartups/StartupBlockingOnStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ public void Configure(IApplicationBuilder app)
// Entry point for the application.
public static void Main(string[] args)
{
var config = WebApplicationConfiguration.GetDefault(args);

var application = new WebApplicationBuilder()
.UseConfiguration(config)
var host = new WebHostBuilder()
.UseDefaultConfiguration(args)
.UseStartup<StartupBlockingOnStart>()
.Build();

using (application)
using (host)
{
application.Start();
host.Start();
Console.ReadLine();
}
}
Expand Down
8 changes: 3 additions & 5 deletions samples/SampleStartups/StartupConfigureAddresses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ public void Configure(IApplicationBuilder app)
// Entry point for the application.
public static void Main(string[] args)
{
var config = WebApplicationConfiguration.GetDefault(args);

var application = new WebApplicationBuilder()
.UseConfiguration(config)
var host = new WebHostBuilder()
.UseDefaultConfiguration(args)
.UseStartup<StartupConfigureAddresses>()
.UseUrls("http://localhost:5000", "http://localhost:5001")
.Build();

application.Run();
host.Run();
}
}
}
6 changes: 3 additions & 3 deletions samples/SampleStartups/StartupExternallyControlled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SampleStartups
{
public class StartupExternallyControlled
{
private IWebApplication _application;
private IWebHost _host;
private readonly List<string> _urls = new List<string>();

// This method gets called by the runtime. Use this method to add services to the container.
Expand All @@ -35,14 +35,14 @@ public StartupExternallyControlled()

public void Start()
{
_application = new WebApplicationBuilder()
_host = new WebHostBuilder()
.UseStartup<StartupExternallyControlled>()
.Start(_urls.ToArray());
}

public void Stop()
{
_application.Dispose();
_host.Dispose();
}

public void AddUrl(string url)
Expand Down
4 changes: 2 additions & 2 deletions samples/SampleStartups/StartupFullControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class StartupFullControl
{
public static void Main(string[] args)
{
var application = new WebApplicationBuilder()
var host = new WebHostBuilder()
.UseServer("Microsoft.AspNet.Server.Kestrel") // Set the server manually
.UseApplicationBasePath(Directory.GetCurrentDirectory()) // Override the application base with the current directory
.UseUrls("http://*:1000", "https://*:902")
Expand All @@ -35,7 +35,7 @@ public static void Main(string[] args)
})
.Build();

application.Run();
host.Run();
}
}

Expand Down
8 changes: 3 additions & 5 deletions samples/SampleStartups/StartupHelloWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ public void Configure(IApplicationBuilder app)
// Entry point for the application.
public static void Main(string[] args)
{
var config = WebApplicationConfiguration.GetDefault(args);

var application = new WebApplicationBuilder()
.UseConfiguration(config)
var host = new WebHostBuilder()
.UseDefaultConfiguration(args)
.UseStartup<StartupHelloWorld>()
.Build();

application.Run();
host.Run();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IHostingEnvironment
/// of the "Hosting:Environment" (on Windows) or "Hosting__Environment" (on Linux &amp; OS X) environment variable.
/// </summary>
// This must be settable!
string EnvironmentName { get; set; }
string EnvironmentName { get; set; }

/// <summary>
/// Gets or sets the absolute path to the directory that contains the web-servable application content files.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
namespace Microsoft.AspNet.Hosting
{
/// <summary>
/// Represents a configured web application
/// Represents a configured web host
/// </summary>
public interface IWebApplication : IDisposable
public interface IWebHost : IDisposable
{
/// <summary>
/// The <see cref="IFeatureCollection"/> exposed by the configured server.
/// </summary>
IFeatureCollection ServerFeatures { get; }

/// <summary>
/// The <see cref="IServiceProvider"/> for the application.
/// The <see cref="IServiceProvider"/> for the host.
/// </summary>
IServiceProvider Services { get; }

Expand Down
73 changes: 73 additions & 0 deletions src/Microsoft.AspNet.Hosting.Abstractions/IWebHostBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting.Server;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNet.Hosting
{
/// <summary>
/// A builder for <see cref="IWebHost"/>
/// </summary>
public interface IWebHostBuilder
Copy link
Member

Choose a reason for hiding this comment

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

Add doc comments to the interface while you're at it?

{
/// <summary>
/// Builds an <see cref="IWebHost"/> which hosts a web application.
/// </summary>
IWebHost Build();

/// <summary>
/// Gets the raw settings to be used by the web host. Values specified here will override
/// the configuration set by <see cref="UseConfiguration(IConfiguration)"/>.
/// </summary>
IDictionary<string, string> Settings { get; }

/// <summary>
/// Specify the <see cref="IConfiguration"/> to be used by the web host. If no configuration is
/// provided to the builder, the default configuration will be used.
/// </summary>
/// <param name="configuration">The <see cref="IConfiguration"/> to be used.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
IWebHostBuilder UseConfiguration(IConfiguration configuration);

/// <summary>
/// Specify the <see cref="IServerFactory"/> to be used by the web host.
/// </summary>
/// <param name="factory">The <see cref="IServerFactory"/> to be used.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
IWebHostBuilder UseServer(IServerFactory factory);

/// <summary>
/// Specify the startup type to be used by the web host.
/// </summary>
/// <param name="startupType">The <see cref="Type"/> to be used.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
IWebHostBuilder UseStartup(Type startupType);

/// <summary>
/// Specify the delegate that is used to configure the services of the web application.
/// </summary>
/// <param name="configureServices">The delegate that configures the <see cref="IServiceCollection"/>.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
IWebHostBuilder ConfigureServices(Action<IServiceCollection> configureServices);

/// <summary>
/// Specify the startup method to be used to configure the web application.
/// </summary>
/// <param name="configureApplication">The delegate that configures the <see cref="IApplicationBuilder"/>.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
IWebHostBuilder Configure(Action<IApplicationBuilder> configureApplication);

/// <summary>
/// Add or replace a setting in <see cref="Settings"/>.
/// </summary>
/// <param name="key">The key of the setting to add or replace.</param>
/// <param name="value">The value of the setting to add or replace.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
IWebHostBuilder UseSetting(string key, string value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Microsoft.AspNet.Hosting
{
public static class WebApplicationDefaults
public static class WebHostDefaults
{
public static readonly string ApplicationKey = "application";
public static readonly string DetailedErrorsKey = "detailedErrors";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.ServiceProcess;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -10,25 +9,25 @@ namespace Microsoft.AspNet.Hosting.WindowsServices
/// <summary>
/// Provides an implementation of a Windows service that hosts ASP.NET.
/// </summary>
public class WebApplicationService : ServiceBase
public class WebHostService : ServiceBase
{
private IWebApplication _application;
private IWebHost _host;
private bool _stopRequestedByWindows;

/// <summary>
/// Creates an instance of <c>WebApplicationService</c> which hosts the specified web application.
/// Creates an instance of <c>WebHostService</c> which hosts the specified web application.
/// </summary>
/// <param name="application">The web application to host in the Windows service.</param>
public WebApplicationService(IWebApplication application)
/// <param name="host">The configured web host containing the web application to host in the Windows service.</param>
public WebHostService(IWebHost host)
{
_application = application;
_host = host;
}

protected sealed override void OnStart(string[] args)
{
OnStarting(args);

_application
_host
.Services
.GetRequiredService<IApplicationLifetime>()
.ApplicationStopped
Expand All @@ -40,7 +39,7 @@ protected sealed override void OnStart(string[] args)
}
});

_application.Start();
_host.Start();

OnStarted();
}
Expand All @@ -49,7 +48,7 @@ protected sealed override void OnStop()
{
_stopRequestedByWindows = true;
OnStopping();
_application?.Dispose();
_host?.Dispose();
OnStopped();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@
namespace Microsoft.AspNet.Hosting.WindowsServices
{
/// <summary>
/// Extensions to <see cref="IWebApplication" for hosting inside a Windows service. />
/// Extensions to <see cref="IWebHost" for hosting inside a Windows service. />
/// </summary>
public static class WebApplicationExtensions
public static class WebHostWindowsServiceExtensions
{
/// <summary>
/// Runs the specified web application inside a Windows service and blocks until the service is stopped.
/// </summary>
/// <param name="application">An instance of the <see cref="IWebApplication"/> to host in the Windows service.</param>
/// <param name="host">An instance of the <see cref="IWebHost"/> to host in the Windows service.</param>
/// <example>
/// This example shows how to use <see cref="WebApplicationService.Run"/>.
/// This example shows how to use <see cref="WebHostService.Run"/>.
/// <code>
/// public class Program
/// {
/// public static void Main(string[] args)
/// {
/// var config = WebApplicationConfiguration.GetDefault(args);
/// var config = WebHostConfiguration.GetDefault(args);
///
/// var application = new WebApplicationBuilder()
/// var host = new WebHostBuilder()
/// .UseConfiguration(config)
/// .Build();
///
/// // This call will block until the service is stopped.
/// application.RunAsService();
/// host.RunAsService();
/// }
/// }
/// </code>
/// </example>
public static void RunAsService(this IWebApplication application)
public static void RunAsService(this IWebHost host)
{
var webApplicationService = new WebApplicationService(application);
ServiceBase.Run(webApplicationService);
var webHostService = new WebHostService(host);
ServiceBase.Run(webHostService);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Hosting.Internal
{
public static class HostingEnvironmentExtensions
{
public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebApplicationOptions options, IConfiguration configuration)
public static void Initialize(this IHostingEnvironment hostingEnvironment, string applicationBasePath, WebHostOptions options, IConfiguration configuration)
{
if (options == null)
{
Expand Down
Loading