- The goal here is to enable components that use hosting abstractions to use
the web host. It lets us start to decouple components from the web host abstractions
where possible while not breaking any existing components. This will allow things
to work in both the generic host and the web host. The one snafu is the WebHostBuilderContext
which has an IHostingEnvironment typed as the AspNetCore.Abstractions type.
- Updated tests.
#1218
* Add BackgroundService, a base class for long running HostedServices
- Today the IHostedService pattern is a StartAsync/StopAsync pattern. Neither of these
methods are supposed to return a long running task that represents an execution. If
you wanted to have some logic run on a timer every 5 minutes, it's unnatural to do so
with simple async idioms. This base class implements IHostedService and exposes
a pattern where a long running async Task can be returned.
- The token passed into ExecuteAsync represents the lifetime of the execution.
- StartAsync and StopAsync were made virtual to allow the derived type to
indicate Start failures.
- Added tests
* Create a sources package to encode the convention followed in our templates to create a WebHost.
* Add an extension method to setup the content root relative to the solution folder.
* Add a factory method to create a WebHostBuilder based on the pattern followed in our template.
* Add IStartupConfigureServicesFilter to wrap ConfigureServices.
* Add IStartupConfigureContainerFilter<TContainerBuilder> to wrap
ConfigureContainer.
* Make StartupLoader build a thunk for configure services that
resolves all instances of IStartupConfigureServicesFilter and
IStartupConfigureContainerFilter<TContainerBuilder> and wraps
invocations to ConfigureServices and ConfigureContainer respectively.
* Refactor building the ConfigureServices callback into a private
builder class due to the increased complexity in the process.