-
-
Notifications
You must be signed in to change notification settings - Fork 158
RFC: Separate Concerns of JsonApiContext #253
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
Comments
Would there be any intention to have the deserializer work outside of a JADNC service - I want to use it in a client context but as it stands this won't work - should I look at another deserializer? |
Hmmmm - looks like I could actually do this on the client by using |
Any update on this? Running into this while testing |
@wisepotato can you be more specific? Is it mocking the interface in general or is there a specific issue you’re consistently hitting in your tests? |
Using the ContextGraph without The controller/HttpContextAccessor is my main issue. I need to do end-to-end testing and cannot mock anything if I need to use the repositories for some business logic testing. |
The JsonApiDotNetCore/test/UnitTests/Builders/DocumentBuilder_Tests.cs Lines 295 to 298 in 3ade2a7
|
I dont want to mock it, I want to actually use it. I want the database calls to be made but JsonApiDotNetCore/src/JsonApiDotNetCore/Services/JsonApiContext.cs Lines 59 to 82 in 8570b21
or more specifically: JsonApiDotNetCore/src/JsonApiDotNetCore/Services/JsonApiContext.cs Lines 69 to 75 in 8570b21
|
Just a thought I was having which is kinda related to I haven't checked it thoroughly, but I think JsonApiContext is the main (if not the only, apart from the resource graph, but thats fine) service that causes a strong coupling between the (de)serialization layer and the controllers/services/repo layer. I think the controllers/services/repo layers are pretty powerful the way they are right now, and on their own they could be very useful for people who do not want to use the JSON:API spec. If we were to detangle |
We're currently reviewing #558 in which |
I think the idea of Api.NETCore is a really good idea - I have actually
tried to create a version of this framework that doesn't do the full
JSONAPI serialization (for when there is no desire to use that level of
complexity) and while it loses some of the benefits of full JSONAPI it's
definitely very useful
w
…On Thu, Oct 3, 2019 at 12:45 PM Maurits Moeys ***@***.***> wrote:
We're currently reviewing #558
<#558> in which
JsonApiContext is completely removed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#253?email_source=notifications&email_token=AABLPDDRXMZXU7DHADXAJZLQMXLPJA5CNFSM4EZNAKQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAH52RA#issuecomment-537910596>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABLPDAHNYE5UUWS6NKNNVDQMXLPJANCNFSM4EZNAKQQ>
.
|
You might be very interested in #558, as it makes sure that this sort of decoupling is more available. |
@wayne-o we're currently getting pretty close to reaching that level. We're moving towards a framework that still has the constraints in the repo/service/controller layers that are more or less implied by json:api spec but in which you're completely free to pick any serialization format you like. Example of such constraint: json:api allows for creation of a resource while simultaneously relating it to an already existing resource, but is not possible to create two resources in one request and relate them. These constraints on the framework are more or less high-level design choices that are derived from json:api spec. Therefore these constraints can be expressed in but are not limited to the json:api format. My goal is to adhere to these constraints but remove the dependency on json:api format of the payload. |
I think that this will open up the project to a LOT mroe people!!
…On Thu, Oct 3, 2019 at 3:33 PM Maurits Moeys ***@***.***> wrote:
@wayne-o <https://github.com/wayne-o> we're currently getting pretty
close to reaching that level. We're moving towards a framework that still
has the constraints in the repo/service/controller layers that are more or
less implied by json:api spec but in which you're completely free to pick
any serialization format you like.
Example of such constraint: json:api allows for creation of a resource
while simultaneously relating it to an already existing resource, but is
not possible to create two resources in one request and relate them.
These constraints on the framework are more or less high-level design
choices that are derived from json:api spec, and therefore can be expressed
in but not limited to the json:api format. My goal is to adhere to these
constraints but remove the dependency on json:api format of the payload.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#253?email_source=notifications&email_token=AABLPDGF2LXDKLXSI5LS2G3QMX7E3A5CNFSM4EZNAKQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAIM6AA#issuecomment-537972480>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABLPDACPYWA2PI62STIPJTQMX7E3ANCNFSM4EZNAKQQ>
.
|
resolved in #558 |
Start Date: N/A
Status: WIP
RFC PR: N/A
Summary
Refactor the
JsonApiContext
into classes with singular responsibilities.Motivation
The
JsonApiContext
is a god container whose members are set in various places during the request cycle. Because of the large set of responsibilities this class takes on, it can make testing difficult. Its role, in general, is to ensure ambient data is available whenever necessary.This was more of an issue during the early stages of development when the architecture was still in flux. Now that the internal APIs are solidifying, we can begin separating this class into single responsibility implementations.
Note: The primary benefit that still exists of the
JsonApiContext
is that it reduces the number of constructor dependencies required for each class.Detailed Design
TODO: map all the consumption points and identify separation strategies
Controllers (#255)
ApplyContext<TController>
. This method is responsible for:RequestEntity
IResourceRequest
that providesGet(/* ... */)
andSet(/* ... */)
methods to replace this functionality.PageManager
JsonApiDotNetCore/src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs
Line 94 in e7c65db
We should be able to remove the direct dependency by moving the functionality into an ActionFilter without any other modifications. However, the functionality defined above still needs to be factored out of the context where possible.
Deserializer
Sets
RequestEntity
. This is redundant with the controller and we should be able to remove this step.JsonApiDotNetCore/src/JsonApiDotNetCore/Serialization/JsonApiDeSerializer.cs
Lines 107 to 108 in e7c65db
Sets
IsBulkOperationRequest
Sets
DocumentMeta
: we should consider storing the deserialized document in the request somewhereSets
AttributesToUpdate
Depends on
_jsonApiContext.Options.SerializerSettings
: we could directly depend onJsonApiOptions
insteadSets
RelationshipsToUpdate
Proposed Approach:
JsonApiDeSerializerFactory
that produces either:JsonApiOperationsDeserializer
JsonApiDeSerializer
(consider aliasing to a more descriptive name)JsonApiOptions
directlyContextGraph
directlyDocumentRequest
type that includes:Documents
orDocument
Phased Implementation
The intent is to make changes in such a way that users of the library can gradually depend on the new structure without forced breaking changes. The rollout of this change will span 4 releases as outlined below:
ApplyContext<T>
, then there is no need for the controller to even depend on theJsonApiContext
. In this case, we would keep the original constructor but provide an implementation that does not require the context:IJsonApiContext
.ObsoleteAttribute
error to trueApp vs. Request vs. Operations
This needs its own issue
The
JsonApiContext
stores three kinds of informationJsonApiOptions
ContextGraph
BasePath
IsRelationshipPath
IsBulkOperationRequest
ControllerType
DocumentMeta
IncludedRelationships
AttributesToUpdate
RelationshipsToUpdate
HasManyRelationshipPointers
HasOneRelationshipPointers
QuerySet
The text was updated successfully, but these errors were encountered: