Adding ConfigureFunctionsWebApplication() (#2782)

This commit is contained in:
Brett Samblanet 2024-10-14 15:32:30 -07:00 коммит произвёл Fabio Cavalcante
Родитель 76e5bb1212
Коммит ea69e61d05
3 изменённых файлов: 25 добавлений и 91 удалений

Просмотреть файл

@ -0,0 +1,23 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using Microsoft.Extensions.Hosting;
namespace Microsoft.Azure.Functions.Worker.Builder;
/// <summary>
/// ASP.NET Core extensions for <see cref="FunctionsApplicationBuilder"/>.
/// </summary>
public static class FunctionsApplicationBuilderAspNetCoreExtensions
{
/// <summary>
/// Configures the worker to use the ASP.NET Core integration, enabling advanced HTTP features.
/// </summary>
/// <param name="builder">The <see cref="FunctionsApplicationBuilder"/> to configure.</param>
/// <returns>The <see cref="FunctionsApplicationBuilder"/> for chaining.</returns>
public static FunctionsApplicationBuilder ConfigureFunctionsWebApplication(this FunctionsApplicationBuilder builder)
{
builder.HostBuilder.ConfigureFunctionsWebApplication();
return builder;
}
}

Просмотреть файл

@ -1,89 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Azure.Functions.Worker.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.Metrics;
using Microsoft.Extensions.Logging;
namespace Microsoft.Extensions.Hosting
{
/// <summary>
/// Placeholder
/// </summary>
public class FunctionsWebApplicationBuilder : IHostApplicationBuilder
{
private readonly HostApplicationBuilder _hostApplicationBuilder;
internal FunctionsWebApplicationBuilder()
{
var configuration = new ConfigurationManager();
_hostApplicationBuilder = new HostApplicationBuilder(new HostApplicationBuilderSettings
{
Configuration = configuration
});
var bootstrapHostBuilder = new BootstrapHostBuilder(_hostApplicationBuilder);
bootstrapHostBuilder.ConfigureFunctionsWebApplication();
InitializeHosting(bootstrapHostBuilder);
}
/// <inheritdoc/>
public IDictionary<object, object> Properties => ((IHostApplicationBuilder)_hostApplicationBuilder).Properties;
IConfigurationManager IHostApplicationBuilder.Configuration => Configuration;
/// <inheritdoc/>
public ConfigurationManager Configuration => _hostApplicationBuilder.Configuration;
/// <inheritdoc/>
public IHostEnvironment Environment { get; private set; }
/// <inheritdoc/>
public ILoggingBuilder Logging => _hostApplicationBuilder.Logging;
/// <inheritdoc/>
public IMetricsBuilder Metrics => _hostApplicationBuilder.Metrics;
/// <inheritdoc />
public IServiceCollection Services => _hostApplicationBuilder.Services;
/// <summary>
/// Placeholder
/// </summary>
/// <returns>placeholder</returns>
public static FunctionsWebApplicationBuilder CreateBuilder()
{
return new FunctionsWebApplicationBuilder();
}
/// <summary>
/// Placeholder
/// </summary>
/// <returns>placeholder</returns>
public IHost Build()
{
return _hostApplicationBuilder.Build();
}
/// <inheritdoc/>
public void ConfigureContainer<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder> factory, Action<TContainerBuilder>? configure = null) where TContainerBuilder : notnull
=> _hostApplicationBuilder.ConfigureContainer(factory, configure);
private void InitializeHosting(BootstrapHostBuilder bootstrapHostBuilder)
{
bootstrapHostBuilder.RunDefaultCallbacks();
// Grab the WebHostBuilderContext from the property bag to use in the ConfigureWebHostBuilder. Then
// grab the IWebHostEnvironment from the webHostContext. This also matches the instance in the IServiceCollection.
var webHostContext = (WebHostBuilderContext)bootstrapHostBuilder.Properties[typeof(WebHostBuilderContext)];
Environment = webHostContext.HostingEnvironment;
//Host = new ConfigureHostBuilder(bootstrapHostBuilder.Context, Configuration, Services);
//WebHost = new ConfigureWebHostBuilder(webHostContext, Configuration, Services);
}
}
}

Просмотреть файл

@ -7,7 +7,7 @@
<!--Version information-->
<VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix>-preview1</VersionSuffix>
<VersionSuffix>-preview2</VersionSuffix>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
@ -24,7 +24,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.23.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0-preview2-20241014.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
</ItemGroup>