Skip to content
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
9 changes: 0 additions & 9 deletions samples/FunctionApp/Program.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -19,12 +16,6 @@ static async Task Main(string[] args)
// #endif
//<docsnippet_startup>
var host = new HostBuilder()
//<docsnippet_configure_app>
.ConfigureAppConfiguration(c =>
{
c.AddCommandLine(args);
})
//</docsnippet_configure_app>
//<docsnippet_middleware>
.ConfigureFunctionsWorkerDefaults()
//</docsnippet_middleware>
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetWorker.Core/Context/BindingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
{
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetWorker.Core/Context/DefaultFunctionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public DefaultFunctionContext(IServiceScopeFactory serviceScopeFactory, IInvocat
}


public override string Id => _invocation.Id;
public override string InvocationId => _invocation.Id;

public override string FunctionId => _invocation.FunctionId;

Expand Down
3 changes: 2 additions & 1 deletion src/DotNetWorker.Core/Context/FunctionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public abstract class FunctionContext
/// 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.
Expand All @@ -30,6 +30,7 @@ public abstract class FunctionContext

/// <summary>
/// Gets the binding context for the current function invocation.
/// This context is used to retrieve binding data.
/// </summary>
public abstract BindingContext BindingContext { get; }

Expand Down
3 changes: 2 additions & 1 deletion src/DotNetWorker.Core/FunctionsApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void LoadFunction(FunctionDefinition definition)

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private static class Log

public static void ModelBindingFeatureUnavailable(ILogger<DefaultFunctionExecutor> logger, FunctionContext context)
{
_modelBindingFeatureUnavailable(logger, context.Id, context.FunctionId, null);
_modelBindingFeatureUnavailable(logger, context.InvocationId, context.FunctionId, null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions src/DotNetWorker.Core/Pipeline/FunctionExecutionDelegate.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
11 changes: 6 additions & 5 deletions src/DotNetWorker/Hosting/FunctionsWorkerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,14 +31,14 @@ public static void RunDefault(Action<IServiceCollection>? configureServices = nu
/// <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();
}
}
Expand Down
34 changes: 26 additions & 8 deletions src/DotNetWorker/Hosting/WorkerHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.Extensions.Hosting
Expand Down Expand Up @@ -108,18 +109,35 @@ public static IHostBuilder ConfigureFunctionsWorkerDefaults(this IHostBuilder bu
/// <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);
}
}
}
7 changes: 7 additions & 0 deletions src/DotNetWorker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/DotNetWorkerTests/TestFunctionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TestFunctionContext(FunctionDefinition functionDefinition, FunctionInvoca

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;

Expand Down
36 changes: 36 additions & 0 deletions test/DotNetWorkerTests/WorkerHostBuilderExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -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"]);
}
}
}
5 changes: 0 additions & 5 deletions test/E2ETests/E2EApps/E2EApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,10 +11,6 @@ class Program
static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureAppConfiguration(c =>
{
c.AddCommandLine(args);
})
.ConfigureFunctionsWorkerDefaults()
.Build();

Expand Down