Skip to content

require registration of resource types #80

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

Merged
merged 2 commits into from
Feb 26, 2015

Conversation

csantero
Copy link
Collaborator

This PR paves the way for polymorphism (#73) and heterogeneous collection support by requiring the user to pre-register all resource types. This will be a major breaking change as existing apps will fail until they add their necessary registrations.

I changed the language of GetJsonKeyForType to GetResouceTypeNameForType because the spec no longer wants primary data to be keyed by type, but rather by the word data. "Resource type name" seemed a more apt description of what we are determining.

I also added a virtual method on ModelManager called CalculateResourceTypeNameForType which will allow sub-classes to override the default strategy for determining the resource type name.

@SphtKr do you have any concerns?

Chris Santero added 2 commits February 25, 2015 13:49
When trying to determine the resource type name for a type "A" that is
not registered but is derived from another type "B" that is, then the
model manager should return the resource type name for type "B". This is
particularly useful when trying to serialize Entity Framework proxies.
@SphtKr
Copy link
Collaborator

SphtKr commented Feb 26, 2015

Yeah, not thrilled about that requirement, but don't see a good way around it right now. Json.Net is able to skirt any registration requirement because it essentially requires you to tell it the type it's deserializing before it starts...with the type key in the resource we won't have that luxury.

@SphtKr
Copy link
Collaborator

SphtKr commented Feb 26, 2015

LGTM. Couple of thoughts for the future, it might make sense to go ahead and put any registered types through the wringer of all the other caching methods, to build up the caches at startup (but that's internal and we can do it later). Also, I'd favor adding a method to add everything in a namespace, and probably some way to add everything in a DbContext, for convenience. The latter will have to go in JSONAPI.EntityFramework somewhere of course...I imagine we should probably have an EF-specific subclass of ModelManager in there at some point, and such a method would make sense there.

csantero added a commit that referenced this pull request Feb 26, 2015
require registration of resource types
@csantero csantero merged commit b83f0df into JSONAPIdotNET:0-4-0 Feb 26, 2015
@csantero csantero deleted the register-types branch February 26, 2015 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants