-1
public class Parent{
  public IEnumerable<Child> Children(Filters filter){
    return new List<Child>() { new Child()};
  }
}

public class Child{
  public string Value(ChildrenFilter filter){
    // Maybe return null, maybe return a string
  }
}

I want to filter the Parent.Children collection depending if the Child.Value is different than null. ex: .Where(child => // child has Value);

But with the code above, I can't seem to use a middleware, as it runs before the Child.Value is called.

Is there a hook for me to apply the filtering logic after the Child.Value has been resolved?

1 Answers1

-2

For my scenario, I managed to plug in a custom serializer, so I have access to the response just before it's serialized.

At this point, the response object it's in a different format, but with a bit of custom logic, I was able to filter what I needed.

  internal class CustomHttpResultSerializer : DefaultHttpResultSerializer
    {
        public override ValueTask SerializeAsync(IExecutionResult result, Stream stream, CancellationToken cancellationToken)
        {
            var queryResult = result as QueryResult;

            // Remove any unwanted results

            return base.SerializeAsync(result, stream, cancellationToken);
        }
    }

Then at Startup:

 services.AddHttpResultSerializer<CustomHttpResultSerializer>();