I have a domain model where I've been successfully using a custom IContractResolver that extends CamelCasePropertyNamesContractResolver to remove specific properties at the controller level using a custom Attribute that implements IControllerConfiguration.
I'm now in a situation where I need to expose those properties I was removing based on a specific Action. My plan was to simple change my contract resolver to this:
public MyContractResolver(bool expose = false)
and update how i use the ContractResolver (i.e. create new JsonSerializerSettings per action).
The problem i'm facing is that the Contracts are being cached for each object and CreateProperties
is not being called on new instances and therefore ignoring the "expose" logic (in fact it's whoever is called first that gets cached).
I'm able to work around this by simply extending my custom contract resolver but i'd like to be able to have 1 that adapts dynamically. Is that possible? Is there a better way to get it change behavior vs modifying the constructor?
Thanks,