Skip to content

Commit

Permalink
React to feedback
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
guardrex committed Jul 19, 2018
1 parent 9ca1592 commit d3c666d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 37 deletions.
10 changes: 4 additions & 6 deletions aspnetcore/fundamentals/host/platform-specific-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ An [IHostingStartup](/dotnet/api/microsoft.aspnetcore.hosting.ihostingstartup) i

## Hosting startup activated from an existing class library

When an `IHostingStartup` enhancement is available in an existing library, the hosting startup types provided by the library can be made available to the app with a [HostingStartup](/dotnet/api/microsoft.aspnetcore.hosting.hostingstartupattribute) attribute.
When an `IHostingStartup` enhancement is available in an existing library, the hosting startup types provided by the library can be made available to the app with a [HostingStartup](/dotnet/api/microsoft.aspnetcore.hosting.hostingstartupattribute) attribute. The entry assembly or the assembly containing the `Startup` class is automatically scanned for the `HostingStartup` attribute.

The [sample app](https://github.com/aspnet/Docs/tree/master/aspnetcore/fundamentals/host/platform-specific-configuration/samples/2.x/HostingStartupSample) includes a Razor Pages app, *HostingStartupApp*, and a class library, *HostingStartupLib*. The class library contains a hosting startup class, `ServiceKeyInjection`, which implements `IHostingStartup`.

Expand All @@ -38,15 +38,13 @@ The app's Index page reads the configuration values for the two keys set by the

*HostingStartupApp/Pages/Index.cshtml.cs*:

[!code-csharp[](platform-specific-configuration/samples/2.x/HostingStartupSample/HostingStartupApp/Pages/Index.cshtml.cs?name=snippet1&highlight=11-12,19-20)]
[!code-csharp[](platform-specific-configuration/samples/2.x/HostingStartupSample/HostingStartupApp/Pages/Index.cshtml.cs?name=snippet1&highlight=5-6,9-10)]

## Discover loaded hosting startup assemblies

To discover hosting startup assemblies loaded by the app or by libraries, enable logging and check the application logs. Errors that occur when loading assemblies are logged. Loaded hosting startup assemblies are logged at the Debug level, and all errors are logged.

The sample app reads the [HostingStartupAssembliesKey](/dotnet/api/microsoft.aspnetcore.hosting.webhostdefaults.hostingstartupassemblieskey) into a `string` array and displays the result in the app's Index page:

[!code-csharp[](platform-specific-configuration/samples/2.x/HostingStartupSample/HostingStartupApp/Pages/Index.cshtml.cs?name=snippet1&highlight=10,16-18)]
Hosting startup assemblies are listed in the [WebHostDefaults.HostingStartupAssembliesKey](/dotnet/api/microsoft.aspnetcore.hosting.webhostdefaults.hostingstartupassemblieskey). Excluded assemblies are listed in the [WebHostDefaults.HostingStartupExcludeAssembliesKey](/dotnet/api/microsoft.aspnetcore.hosting.webhostdefaults.hostingstartupexcludeassemblieskey). For more information, see [Web Host: Hosting Startup Assemblies](xref:fundamentals/host/web-host#hosting-startup-assemblies) and [Web Host: Hosting Startup Exclude Assemblies](xref:fundamentals/host/web-host#hosting-startup-exclude-assemblies).

## Disable automatic loading of hosting startup assemblies

Expand Down Expand Up @@ -84,7 +82,7 @@ An `IHostingStartup` enhancement is deployed as an assembly based on a console a

[!code-xml[](platform-specific-configuration/samples-snapshot/2.x/StartupEnhancement.csproj)]

A [HostingStartup](/dotnet/api/microsoft.aspnetcore.hosting.hostingstartupattribute) attribute identifies a class as an implementation of `IHostingStartup` for loading and execution when building the [IWebHost](/dotnet/api/microsoft.aspnetcore.hosting.iwebhost). In the following example, the namespace is `StartupEnhancement`, and the class is `StartupEnhancementHostingStartup`:
A [HostingStartup](/dotnet/api/microsoft.aspnetcore.hosting.hostingstartupattribute) attribute identifies a class as an implementation of `IHostingStartup` for loading and execution when building the [IWebHost](/dotnet/api/microsoft.aspnetcore.hosting.iwebhost). The entry assembly or the assembly containing the `Startup` class is automatically scanned for the `HostingStartup` attribute. In the following example, the namespace is `StartupEnhancement`, and the class is `StartupEnhancementHostingStartup`:

[!code-csharp[](platform-specific-configuration/samples-snapshot/2.x/StartupEnhancement.cs?name=snippet1)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@
</div>
</div>

<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Loaded Hosting Startup Assemblies</h3>
</div>
<div class="panel-body">
<h4>Assemblies</h4>
<ul>
@foreach (var assembly in Model.LoadedHostingStartupAssemblies)
{
<li>@assembly</li>
}
</ul>
</div>
</div>
</div>
</div>

<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration;

namespace HostingStartupApp.Pages
{
#region snippet1
public class IndexModel : PageModel
{
private readonly IConfiguration _config;

public IndexModel(IConfiguration config)
{
_config = config;
ServiceKey_Development = config["DevAccount"];
ServiceKey_Production = config["ProdAccount"];
}

public string[] LoadedHostingStartupAssemblies { get; private set; }
public string ServiceKey_Development { get; private set; }
public string ServiceKey_Production { get; private set; }

public void OnGet()
{
LoadedHostingStartupAssemblies =
_config[WebHostDefaults.HostingStartupAssembliesKey]
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0];
ServiceKey_Development = _config["DevAccount"];
ServiceKey_Production = _config["ProdAccount"];
}
}
#endregion
Expand Down

0 comments on commit d3c666d

Please sign in to comment.