-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot replace ContractResolver, even with a passthrough! #701
Comments
In order to make this work, I had to do:
That code smells pretty bad. :) |
Also, honestly, I need that first example to work. I have an alternate contract resolver from a third party that isn't going to be able to derive from |
Some json converters need the original C# request to piece to response back together (_msearch, _mget, others). This is the reason I need to inject state that I can pull out inside of the converter and the contractresolver is the only place, which is the reason that NEST only works (or should) with a subclass of ElasticContractResolver registered. Im at a conference today and tomorrow but will look into seeing how we can make this smell a little less 👍 |
Awesome, thanks! By the way, the second example is a subclass of |
Can't you pass something into the ctor of the converters that would then let it get at state without going through the resolver? |
I could but you want resolvers to be cached aggressively. If you use This is why i.e a stateless multisearch converter is registered in the contract that tries to get the state out of the piggybackconverter attached to the contract resolver. All the deserialization uses the same json settings object unless you call deserialize with a stateful deserializer in which case deserialize is called with a new JsonSettings and new ElasticContractResolver. This scopes that deserialization but because the contract uses shared cache state if I pass in a stateful MultiSearchConverter it won't have precedence over the already cached MultiSearchConver which is why it needs to This scoped / stateful deserialization is also why doing Deserialization with something other then JSON.NET in NEST is not possible. Its not pretty but its a major performance boost. |
I'm not arguing against using a custom contract resolver; the performance improvement is totally worth it. I'm just arguing against storing some of this information in that resolver, vs. in some other location that you can then pass into the ctor of the converters as you hook them up to your custom resolver. By the time I replace your resolver with my own (which still hands off 99% of the work to yours) your converters should already be hooked into the original contract resolver and I should be able to proxy contract creation requests to it. |
So the actual method that needs piggyback state is;
right now I can just do a property check in this method:
The only other place I can think of is to have a static I'm all ears for suggestions ! :) |
I wouldn't go with a static dictionary, but perhaps a |
Actually, I don't know that this would work, but, could you subclass Json.NET's |
That sounds so simple its probably going to work! (I cant remember actually going that route). |
I found an easier way to make this work without having to completely change the way you do this. Take a look at #705. |
Here's an example test case that DOES work:
Now here's two different test cases that do NOT work:
and the second example:
The text was updated successfully, but these errors were encountered: