Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 8 additions & 11 deletions src/DotNetWorker/Context/DefaultFunctionExecutionContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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;
Expand All @@ -20,9 +20,9 @@ internal class DefaultFunctionExecutionContext : FunctionExecutionContext, IDisp
public DefaultFunctionExecutionContext(IServiceScopeFactory serviceScopeFactory, FunctionInvocation invocation,
FunctionDefinition definition)
{
_serviceScopeFactory = serviceScopeFactory;
Invocation = invocation;
FunctionDefinition = definition;
_serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
Invocation = invocation ?? throw new ArgumentNullException(nameof(invocation));
FunctionDefinition = definition ?? throw new ArgumentNullException(nameof(definition));
OutputBindings = new Dictionary<string, object>();
}

Expand All @@ -32,7 +32,7 @@ public DefaultFunctionExecutionContext(IServiceScopeFactory serviceScopeFactory,

public override object? InvocationResult { get; set; }

public override InvocationLogger Logger { get; set; }
public override InvocationLogger? Logger { get; set; }

public override IDictionary<string, object> OutputBindings { get; }

Expand All @@ -42,19 +42,16 @@ public override IServiceProvider InstanceServices
{
get
{
if (_instanceServicesScope == null && _serviceScopeFactory != null)
if (_instanceServicesScope == null)
{
_instanceServicesScope = _serviceScopeFactory.CreateScope();
_instanceServices = _instanceServicesScope.ServiceProvider;
}

return _instanceServices;
return _instanceServices!;
}

set
{
_instanceServices = value;
}
set => _instanceServices = value;
}

public virtual void Dispose()
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetWorker/Context/FunctionExecutionContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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;
Expand All @@ -18,7 +18,7 @@ public abstract class FunctionExecutionContext

public abstract object? InvocationResult { get; set; }

public abstract InvocationLogger Logger { get; set; }
public abstract InvocationLogger? Logger { get; set; }

// TODO: Double-check previous projects for layout of FunctionInvocation, Bindings, etc
public abstract IDictionary<string, object> OutputBindings { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetWorker/Converters/Converter/ConverterContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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 Microsoft.Azure.Functions.Worker.Definition;
Expand All @@ -10,7 +10,7 @@ internal abstract class ConverterContext
{
public abstract FunctionParameter Parameter { get; set; }

public abstract object Source { get; set; }
public abstract object? Source { get; set; }

public abstract FunctionExecutionContext ExecutionContext { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Undo this?


using Microsoft.Azure.Functions.Worker.Definition;
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetWorker/Converters/ExactMatchConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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.

namespace Microsoft.Azure.Functions.Worker.Converters
Expand All @@ -7,7 +7,7 @@ internal class ExactMatchConverter : IConverter
{
public bool TryConvert(ConverterContext context, out object? target)
{
if (context.Source.GetType() == context.Parameter.Type)
if (context.Source?.GetType() == context.Parameter.Type)
{
target = context.Source;
return true;
Expand Down
13 changes: 7 additions & 6 deletions src/DotNetWorker/DefaultOutputBinding.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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.Collections.Generic;
Expand All @@ -9,22 +9,23 @@ namespace Microsoft.Azure.Functions.Worker
internal class DefaultOutputBinding<T> : OutputBinding<T>
{
private readonly FunctionParameter _param;
private readonly IDictionary<string, object> _outputBindings;
private readonly IDictionary<string, object?> _outputBindings;

public DefaultOutputBinding(FunctionParameter param, IDictionary<string, object> outputBindings)
public DefaultOutputBinding(FunctionParameter param, IDictionary<string, object?> outputBindings)
{
_param = param;
_outputBindings = outputBindings;
}

public override void SetValue(T value)
public override void SetValue(T? value)
{
_outputBindings[_param.Name] = value;
}

internal override T GetValue()
internal override T? GetValue()
{
return (T)_outputBindings[_param.Name];
var value = _outputBindings[_param.Name];
return (T)value;
}
}
}
11 changes: 9 additions & 2 deletions src/DotNetWorker/Definition/DefaultFunctionDefinitionFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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;
Expand Down Expand Up @@ -54,9 +54,16 @@ public FunctionDefinition Create(FunctionLoadRequest request)

MethodInfo? methodInfo = functionType?.GetMethod(methodName);

if (methodInfo == null)
{
throw new InvalidOperationException($"Method '{methodName}' specified in {nameof(FunctionMetadata.EntryPoint)} was not found. This function cannot be created.");
}

IFunctionInvoker invoker = _functionInvokerFactory.Create(methodInfo);

IEnumerable<FunctionParameter> parameters = methodInfo.GetParameters().Select(p => new FunctionParameter(p.Name, p.ParameterType));
IEnumerable<FunctionParameter> parameters = methodInfo.GetParameters()
.Where(p => p.Name != null)
.Select(p => new FunctionParameter(p.Name!, p.ParameterType));

return new DefaultFunctionDefinition(metadata, invoker, parameters);
}
Expand Down
17 changes: 6 additions & 11 deletions src/DotNetWorker/Definition/FunctionMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
// 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.Collections.Immutable;
using System.Reflection;

namespace Microsoft.Azure.Functions.Worker
{
public class FunctionMetadata
public abstract class FunctionMetadata
{
public string? PathToAssembly { get; set; }

public string? EntryPoint { get; set; }
public abstract string PathToAssembly { get; set; }

public string? TypeName { get; set; }
public abstract string EntryPoint { get; set; }

public string? FunctionId { get; set; }
public abstract string FunctionId { get; set; }

public string? FuncName { get; set; }
public abstract string Name { get; set; }
}
}
24 changes: 24 additions & 0 deletions src/DotNetWorker/Definition/GrpcFunctionMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.IO;
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;

namespace Microsoft.Azure.Functions.Worker.Definition
{
internal class GrpcFunctionMetadata : FunctionMetadata
{
public GrpcFunctionMetadata(FunctionLoadRequest loadRequest)
{
EntryPoint = loadRequest.Metadata.EntryPoint;
Name = loadRequest.Metadata.Name;
PathToAssembly = Path.GetFullPath(loadRequest.Metadata.ScriptFile);
FunctionId = loadRequest.FunctionId;
}

public override string PathToAssembly { get; set; }

public override string EntryPoint { get; set; }

public override string FunctionId { get; set; }

public override string Name { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/DotNetWorker/IFunctionActivator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another with just header changes


using System;
Expand Down
6 changes: 3 additions & 3 deletions src/DotNetWorker/Invocation/DefaultFunctionExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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.Linq;
Expand All @@ -12,8 +12,8 @@ internal class DefaultFunctionExecutor : IFunctionExecutor
public async Task ExecuteAsync(FunctionExecutionContext context)
{
var invoker = context.FunctionDefinition.Invoker;
object instance = invoker.CreateInstance(context.InstanceServices);
object result = await invoker.InvokeAsync(instance, context.FunctionDefinition.Parameters.Select(p => p.Value).ToArray());
object? instance = invoker.CreateInstance(context.InstanceServices);
object? result = await invoker.InvokeAsync(instance, context.FunctionDefinition.Parameters.Select(p => p.Value).ToArray());
context.InvocationResult = result;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/DotNetWorker/Invocation/DefaultFunctionInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.

#nullable disable
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all of these types that came straight from WebJobs, I've just disabled nullable completely. This was a big source of warnings.


using System;
using System.Threading.Tasks;

Expand All @@ -24,10 +26,10 @@ public object CreateInstance(IServiceProvider instanceServices)
return FunctionActivator.CreateInstance<TInstance>(instanceServices);
}

public Task<object?> InvokeAsync(object instance, object[] arguments)
public Task<object> InvokeAsync(object instance, object[] arguments)
{
return _methodInvoker.InvokeAsync((TInstance)instance, arguments)
.ContinueWith<object?>(t => t.Result);
.ContinueWith<object>(t => t.Result);
}
}
}
6 changes: 4 additions & 2 deletions src/DotNetWorker/Invocation/DefaultMethodInvokerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.

#nullable disable

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -63,7 +65,7 @@ public IMethodInvoker<TInstance, TReturn> Create<TInstance, TReturn>(MethodInfo
if (argumentType.IsByRef)
{
// The type of the local variable (and object in the arguments array) should be T rather than T&.
argumentType = argumentType.GetElementType();
argumentType = argumentType.GetElementType()!;
}

// T argumentN
Expand Down
6 changes: 4 additions & 2 deletions src/DotNetWorker/Invocation/IFunctionInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.

#nullable disable

using System;
using System.Threading.Tasks;

Expand All @@ -10,6 +12,6 @@ public interface IFunctionInvoker
{
object CreateInstance(IServiceProvider instanceServices);

Task<object?> InvokeAsync(object instance, object?[] arguments);
Task<object> InvokeAsync(object instance, object[] arguments);
}
}
4 changes: 3 additions & 1 deletion src/DotNetWorker/Invocation/IMethodInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.

#nullable disable

using System.Threading.Tasks;

namespace Microsoft.Azure.Functions.Worker.Invocation
Expand Down
4 changes: 3 additions & 1 deletion src/DotNetWorker/Invocation/MethodInvokerWithReturnValue.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.

#nullable disable

using System;
using System.Threading.Tasks;

Expand Down
4 changes: 3 additions & 1 deletion src/DotNetWorker/Invocation/TaskMethodInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.

#nullable disable

using System;
using System.Diagnostics;
using System.Threading.Tasks;
Expand Down
4 changes: 3 additions & 1 deletion src/DotNetWorker/Invocation/VoidMethodInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.

#nullable disable

using System;
using System.Threading.Tasks;

Expand Down
4 changes: 3 additions & 1 deletion src/DotNetWorker/Invocation/VoidTaskMethodInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +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.

#nullable disable

using System;
using System.Threading.Tasks;

Expand Down
13 changes: 11 additions & 2 deletions src/DotNetWorker/Logging/InvocationLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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;
Expand All @@ -22,7 +22,7 @@ public InvocationLogger(string invocationId, ChannelWriter<StreamingMessage> cha

public IDisposable BeginScope<TState>(TState state)
{
return null;
return EmptyDisposable.Instance;
}

public bool IsEnabled(LogLevel logLevel)
Expand Down Expand Up @@ -67,5 +67,14 @@ private static Level ToRpcLogLevel(LogLevel logLevel)
return Level.None;
}
}

private class EmptyDisposable : IDisposable
{
public static IDisposable Instance = new EmptyDisposable();

public void Dispose()
{
}
}
}
}
4 changes: 2 additions & 2 deletions src/DotNetWorker/NullFunctionActivator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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;
Expand All @@ -13,7 +13,7 @@ private NullFunctionActivator()

public static NullFunctionActivator Instance { get; } = new NullFunctionActivator();

public T CreateInstance<T>(IServiceProvider services)
public T? CreateInstance<T>(IServiceProvider services)
{
return default(T);
}
Expand Down
Loading