Api updates (#262)
This commit is contained in:
Родитель
19e4121de7
Коммит
55452699ad
|
@ -1,10 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Functions.Worker.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
|
@ -19,12 +16,6 @@ namespace FunctionApp
|
|||
// #endif
|
||||
//<docsnippet_startup>
|
||||
var host = new HostBuilder()
|
||||
//<docsnippet_configure_app>
|
||||
.ConfigureAppConfiguration(c =>
|
||||
{
|
||||
c.AddCommandLine(args);
|
||||
})
|
||||
//</docsnippet_configure_app>
|
||||
//<docsnippet_middleware>
|
||||
.ConfigureFunctionsWorkerDefaults()
|
||||
//</docsnippet_middleware>
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
namespace Microsoft.Azure.Functions.Worker
|
||||
{
|
||||
/// <summary>
|
||||
/// Exposes binding infomation for a given funcion context.
|
||||
/// Exposes binding infomation for a given function context.
|
||||
/// </summary>
|
||||
public abstract class BindingContext
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Microsoft.Azure.Functions.Worker
|
|||
}
|
||||
|
||||
|
||||
public override string Id => _invocation.Id;
|
||||
public override string InvocationId => _invocation.Id;
|
||||
|
||||
public override string FunctionId => _invocation.FunctionId;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Microsoft.Azure.Functions.Worker
|
|||
/// Gets the invocation ID.
|
||||
/// This identifier is unique to an invocation.
|
||||
/// </summary>
|
||||
public abstract string Id { get; }
|
||||
public abstract string InvocationId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the function ID, typically assigned by the host.
|
||||
|
@ -30,6 +30,7 @@ namespace Microsoft.Azure.Functions.Worker
|
|||
|
||||
/// <summary>
|
||||
/// Gets the binding context for the current function invocation.
|
||||
/// This context is used to retrieve binding data.
|
||||
/// </summary>
|
||||
public abstract BindingContext BindingContext { get; }
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Functions.Worker.Diagnostics;
|
||||
using Microsoft.Azure.Functions.Worker.Middleware;
|
||||
using Microsoft.Azure.Functions.Worker.Pipeline;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
@ -57,7 +58,7 @@ namespace Microsoft.Azure.Functions.Worker
|
|||
|
||||
public Task InvokeFunctionAsync(FunctionContext context)
|
||||
{
|
||||
var scope = new FunctionInvocationScope(context.FunctionDefinition.Name, context.Id);
|
||||
var scope = new FunctionInvocationScope(context.FunctionDefinition.Name, context.InvocationId);
|
||||
using (_logger.BeginScope(scope))
|
||||
{
|
||||
return _functionExecutionDelegate(context);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Azure.Functions.Worker.Middleware;
|
||||
using Microsoft.Azure.Functions.Worker.Pipeline;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Azure.Functions.Worker.Pipeline;
|
||||
using Microsoft.Azure.Functions.Worker.Middleware;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Middleware;
|
||||
using Microsoft.Azure.Functions.Worker.OutputBindings;
|
||||
|
@ -14,7 +13,7 @@ namespace Microsoft.Extensions.Hosting
|
|||
/// <summary>
|
||||
/// Provides extension methods to work with Worker Middleware against a <see cref="IHostBuilder"/>.
|
||||
/// </summary>
|
||||
public static class WorkerMiddlewareWorkerApplicationBuilderExtensions
|
||||
public static class MiddlewareWorkerApplicationBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures the <see cref="IFunctionsWorkerApplicationBuilder"/> to use the default set of middleware used by the worker, in the following order:
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Microsoft.Azure.Functions.Worker.Invocation
|
|||
|
||||
public static void ModelBindingFeatureUnavailable(ILogger<DefaultFunctionExecutor> logger, FunctionContext context)
|
||||
{
|
||||
_modelBindingFeatureUnavailable(logger, context.Id, context.FunctionId, null);
|
||||
_modelBindingFeatureUnavailable(logger, context.InvocationId, context.FunctionId, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Functions.Worker.Pipeline;
|
||||
using Microsoft.Azure.Functions.Worker.Middleware;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker.OutputBindings
|
||||
{
|
||||
|
|
|
@ -4,15 +4,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Functions.Worker.Middleware;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker.Pipeline
|
||||
{
|
||||
internal class DefaultInvocationPipelineBuilder<Context> : IInvocationPipelineBuilder<Context>
|
||||
{
|
||||
private readonly IList<Func<FunctionExecutionDelegate, FunctionExecutionDelegate>> _middlewareCollection =
|
||||
private readonly IList<Func<FunctionExecutionDelegate, FunctionExecutionDelegate>> _middlewareCollection =
|
||||
new List<Func<FunctionExecutionDelegate, FunctionExecutionDelegate>>();
|
||||
|
||||
public IInvocationPipelineBuilder<Context> Use(Func<FunctionExecutionDelegate, FunctionExecutionDelegate> middleware)
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker.Pipeline
|
||||
namespace Microsoft.Azure.Functions.Worker.Middleware
|
||||
{
|
||||
/// <summary>
|
||||
/// A delegate that can process an event.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Azure.Functions.Worker.Middleware;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker.Pipeline
|
||||
{
|
||||
|
|
|
@ -4,11 +4,12 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Microsoft.Extensions.Hosting
|
||||
namespace Microsoft.Azure.Functions.Worker
|
||||
{
|
||||
/// <summary>
|
||||
/// Hosing helpers to work with Azure Functions Workers
|
||||
/// Hosting helpers to work with Azure Functions Workers
|
||||
/// </summary>
|
||||
public static class FunctionsWorkerHost
|
||||
{
|
||||
|
@ -30,14 +31,14 @@ namespace Microsoft.Extensions.Hosting
|
|||
/// <returns>A <see cref="Task"/> that will complete when the host shuts down.</returns>
|
||||
public async static Task RunDefaultAsync(Action<IServiceCollection>? configureService = null)
|
||||
{
|
||||
var builder = Host.CreateDefaultBuilder()
|
||||
.ConfigureFunctionsWorkerDefaults();
|
||||
var builder = Host.CreateDefaultBuilder()
|
||||
.ConfigureFunctionsWorkerDefaults();
|
||||
|
||||
if (configureService is not null)
|
||||
{
|
||||
builder.ConfigureServices(configureService);
|
||||
}
|
||||
|
||||
|
||||
await builder.Build().RunAsync();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.Extensions.Hosting
|
||||
|
@ -109,18 +110,35 @@ namespace Microsoft.Extensions.Hosting
|
|||
/// <returns>The <see cref="IHostBuilder"/>.</returns>
|
||||
public static IHostBuilder ConfigureFunctionsWorkerDefaults(this IHostBuilder builder, Action<HostBuilderContext, IFunctionsWorkerApplicationBuilder> configure, Action<WorkerOptions> configureOptions)
|
||||
{
|
||||
builder.ConfigureServices((context, services) =>
|
||||
{
|
||||
IFunctionsWorkerApplicationBuilder appBuilder = services.AddFunctionsWorkerDefaults(configureOptions);
|
||||
builder
|
||||
.ConfigureAppConfiguration(configBuilder =>
|
||||
{
|
||||
var cmdLine = Environment.GetCommandLineArgs();
|
||||
RegisterCommandLine(configBuilder, cmdLine);
|
||||
})
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
IFunctionsWorkerApplicationBuilder appBuilder = services.AddFunctionsWorkerDefaults(configureOptions);
|
||||
|
||||
// Call the provided configuration prior to adding default middleware
|
||||
configure(context, appBuilder);
|
||||
// Call the provided configuration prior to adding default middleware
|
||||
configure(context, appBuilder);
|
||||
|
||||
// Add default middleware
|
||||
appBuilder.UseDefaultWorkerMiddleware();
|
||||
});
|
||||
// Add default middleware
|
||||
appBuilder.UseDefaultWorkerMiddleware();
|
||||
});
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
internal static void RegisterCommandLine(IConfigurationBuilder builder, string[] cmdLine)
|
||||
{
|
||||
if (cmdLine.Length > 0 &&
|
||||
!cmdLine[0].StartsWith("--"))
|
||||
{
|
||||
cmdLine[0] = $"\"{cmdLine[0]}\"";
|
||||
}
|
||||
|
||||
builder.AddCommandLine(cmdLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.Azure.Functions.Worker.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001005148be37ac1d9f58bd40a2e472c9d380d635b6048278f7d47480b08c928858f0f7fe17a6e4ce98da0e7a7f0b8c308aecd9e9b02d7e9680a5b5b75ac7773cec096fbbc64aebd429e77cb5f89a569a79b28e9c76426783f624b6b70327eb37341eb498a2c3918af97c4860db6cdca4732787150841e395a29cfacb959c1fd971c1")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Azure.Functions.Worker.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace Microsoft.Azure.Functions.Worker.Tests
|
|||
|
||||
public override IInvocationFeatures Features { get; } = new InvocationFeatures(Enumerable.Empty<IInvocationFeatureProvider>());
|
||||
|
||||
public override string Id => _invocation.Id;
|
||||
public override string InvocationId => _invocation.Id;
|
||||
|
||||
public override string FunctionId => _invocation.FunctionId;
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker.Tests
|
||||
{
|
||||
public class WorkerHostBuilderExtensionsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("/home/usr/", "\"/home/usr/\"")]
|
||||
[InlineData(null, "--host")]
|
||||
public void QuoteFirstArg(string firstArg, string expected)
|
||||
{
|
||||
var cmdLineList = new List<string> { "--host", "127.0.0.1" };
|
||||
|
||||
if (firstArg != null)
|
||||
{
|
||||
cmdLineList.Insert(0, firstArg);
|
||||
}
|
||||
|
||||
var cmdLine = cmdLineList.ToArray();
|
||||
|
||||
var configBuilder = new ConfigurationBuilder();
|
||||
WorkerHostBuilderExtensions.RegisterCommandLine(configBuilder, cmdLine);
|
||||
|
||||
Assert.Equal(expected, cmdLine[0]);
|
||||
|
||||
var config = configBuilder.Build();
|
||||
Assert.Equal("127.0.0.1", config["host"]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Microsoft.Azure.Functions.Worker.E2EApps.CosmosApp
|
||||
|
@ -12,10 +11,6 @@ namespace Microsoft.Azure.Functions.Worker.E2EApps.CosmosApp
|
|||
static async Task Main(string[] args)
|
||||
{
|
||||
var host = new HostBuilder()
|
||||
.ConfigureAppConfiguration(c =>
|
||||
{
|
||||
c.AddCommandLine(args);
|
||||
})
|
||||
.ConfigureFunctionsWorkerDefaults()
|
||||
.Build();
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче