コード例 #1
0
        public DefaultFunctionContext(IServiceScopeFactory serviceScopeFactory, IInvocationFeatures features)
        {
            _serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
            Features             = features ?? throw new ArgumentNullException(nameof(features));

            _invocation        = features.Get <FunctionInvocation>() ?? throw new InvalidOperationException($"The '{nameof(FunctionInvocation)}' feature is required.");
            FunctionDefinition = features.Get <FunctionDefinition>() ?? throw new InvalidOperationException($"The {nameof(Worker.FunctionDefinition)} feature is required.");
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        /// <summary>
        /// Gets a feature of type <typeparamref name="T"/> from the <see cref="IInvocationFeatures"/>.
        /// </summary>
        /// <typeparam name="T">The type of the feature to get.</typeparam>
        /// <param name="features">The <see cref="IInvocationFeatures"/>.</param>
        /// <returns>A feature object of type <typeparamref name="T"/>.</returns>
        /// <exception cref="InvalidOperationException">There is no feature of type <typeparamref name="T"/>.</exception>
        public static T GetRequired <T>(this IInvocationFeatures features)
        {
            var feature = features.Get <T>();

            if (feature is null)
            {
                throw new InvalidOperationException($"No feature is registered with the type {typeof(T)}.");
            }

            return(feature);
        }
コード例 #4
0
 /// <summary>
 /// Tries to get a feature of type <typeparamref name="T"/> from the <see cref="IInvocationFeatures"/>.
 /// </summary>
 /// <typeparam name="T">The type of the feature to get.</typeparam>
 /// <param name="features">The <see cref="IInvocationFeatures"/>.</param>
 /// <param name="feature">The feature, if found. Otherwise, null.</param>
 /// <returns>True if the feature was found. Otherwise, false.</returns>
 public static bool TryGet <T>(this IInvocationFeatures features, out T?feature)
 {
     feature = features.Get <T>();
     return(feature is not null);
 }