public void ApplyConfiguration(ParameterInfo parameter, ObjectFieldDescriptor descriptor)
    {
        switch (_kind)
        {
        case ServiceKind.Pooled:
            UseDbContext <TDbContext>(descriptor.Extend().Definition);
            break;

        case ServiceKind.Synchronized:
            ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, _kind);
            break;

        case ServiceKind.Resolver:
            ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, _kind);
            ObjectFieldDefinition     definition            = descriptor.Extend().Definition;
            FieldMiddlewareDefinition placeholderMiddleware =
                new(_ => _ => throw new NotSupportedException(), key : ToList);
            FieldMiddlewareDefinition serviceMiddleware =
                definition.MiddlewareDefinitions.Last(t => t.Key == PooledService);
            var index = definition.MiddlewareDefinitions.IndexOf(serviceMiddleware) + 1;
            definition.MiddlewareDefinitions.Insert(index, placeholderMiddleware);
            AddCompletionMiddleware(definition, placeholderMiddleware);
            break;
        }
    }
Exemplo n.º 2
0
    internal static void AddCompletionMiddleware(
        ObjectFieldDefinition definition,
        FieldMiddlewareDefinition placeholderMiddleware)
    {
        if (definition.ResultType is null)
        {
            definition.MiddlewareDefinitions.Remove(placeholderMiddleware);
            return;
        }

        if (TryExtractEntityType(definition.ResultType, out Type? entityType))
        {
            Type middleware = typeof(ToListMiddleware <>).MakeGenericType(entityType);
            var  index      = definition.MiddlewareDefinitions.IndexOf(placeholderMiddleware);
            definition.MiddlewareDefinitions[index] =
                new(Create(middleware), key: WellKnownMiddleware.ToList);
            return;
        }

        if (IsExecutable(definition.ResultType))
        {
            Type middleware = typeof(ExecutableMiddleware);
            var  index      = definition.MiddlewareDefinitions.IndexOf(placeholderMiddleware);
            definition.MiddlewareDefinitions[index] =
                new(Create(middleware), key : WellKnownMiddleware.ToList);
        }

        definition.MiddlewareDefinitions.Remove(placeholderMiddleware);
    }