public FunctionContext CreateContext(IInvocationFeatures features) { var invocation = features.Get <FunctionInvocation>() ?? throw new InvalidOperationException($"The {nameof(FunctionInvocation)} feature is required."); var functionDefinition = _functionMap[invocation.FunctionId]; features.Set <FunctionDefinition>(functionDefinition); return(_functionContextFactory.Create(features)); }
internal static async Task <InvocationResponse> InvocationRequestHandlerAsync(InvocationRequest request, IFunctionsApplication application, IInvocationFeaturesFactory invocationFeaturesFactory, ObjectSerializer serializer, IOutputBindingsInfoProvider outputBindingsInfoProvider) { FunctionContext? context = null; FunctionInvocation?invocation = null; InvocationResponse response = new() { InvocationId = request.InvocationId }; try { invocation = new GrpcFunctionInvocation(request); IInvocationFeatures invocationFeatures = invocationFeaturesFactory.Create(); invocationFeatures.Set <FunctionInvocation>(invocation); context = application.CreateContext(invocationFeatures); invocationFeatures.Set <IFunctionBindingsFeature>(new GrpcFunctionBindingsFeature(context, request, outputBindingsInfoProvider)); await application.InvokeFunctionAsync(context); var functionBindings = context.GetBindings(); foreach (var binding in functionBindings.OutputBindingData) { var parameterBinding = new ParameterBinding { Name = binding.Key }; if (binding.Value is not null) { parameterBinding.Data = await binding.Value.ToRpcAsync(serializer); } response.OutputData.Add(parameterBinding); } if (functionBindings.InvocationResult != null) { TypedData?returnVal = await functionBindings.InvocationResult.ToRpcAsync(serializer); response.ReturnValue = returnVal; } response.Result = new StatusResult { Status = StatusResult.Types.Status.Success }; } catch (Exception ex) { response.Result = new StatusResult { Exception = ex.ToRpcException(), Status = StatusResult.Types.Status.Failure }; } finally { (context as IDisposable)?.Dispose(); } return(response); }