Skip to content

Feat: added handler methods to intercept jsonapi entity framework#116

Merged
csantero merged 4 commits intoJSONAPIdotNET:masterfrom
spike83:intercepting-on-create-update-delete
Aug 10, 2016
Merged

Feat: added handler methods to intercept jsonapi entity framework#116
csantero merged 4 commits intoJSONAPIdotNET:masterfrom
spike83:intercepting-on-create-update-delete

Conversation

@spike83
Copy link
Contributor

@spike83 spike83 commented Aug 9, 2016

  • intercept for custom entity manipulations
  • current principal is providet into interception methods
    => so we can handle things like user-created or simple authorization tasks

@csantero
Copy link
Collaborator

csantero commented Aug 9, 2016

@spike83 I do not want to add a member to IDocumentMaterializer if we can avoid it. You can achieve the same effect in your project by making a derived class of EntityFrameworkDocumentMaterializer that uses constructor injection of IPrincipal, and it wouldn't require any interface changes in the main library.

@spike83
Copy link
Contributor Author

spike83 commented Aug 9, 2016

@csantero ok. How and where would you register the principal?

@csantero
Copy link
Collaborator

csantero commented Aug 9, 2016

@spike83 In my project I do something like the following using Autofac and Owin:

            builder.Register(ctx => HttpContext.Current.GetOwinContext()).As<IOwinContext>();

            builder
                .Register((c, p) =>
                {
                    var owin = c.Resolve<IOwinContext>();
                    return owin.Authentication.User;
                })
                .As<IPrincipal>()
                .InstancePerRequest();

Then you can just inject IPrincipal into any request-scoped class's constructor, such as the document materializer.

@csantero
Copy link
Collaborator

csantero commented Aug 9, 2016

@spike83 do the OnCreate etc. methods need to return the same record they were passed in? It seems to me they could just return Tasks.

@csantero csantero merged commit 8dd97a9 into JSONAPIdotNET:master Aug 10, 2016
@csantero
Copy link
Collaborator

Thanks!

@spike83 spike83 deleted the intercepting-on-create-update-delete branch August 17, 2016 07:19
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