graphql-workshop icon indicating copy to clipboard operation
graphql-workshop copied to clipboard

Session 3: UseApplicationDbContextAttribute not necessary?

Open MisterGoodcat opened this issue 2 years ago • 4 comments

I'm trying to understand why creating a separate UseApplicationDbContextAttribute (and the IObjectFieldDescriptor extension) would be necessary at all (steps 5+6 and usage later). I've been loosely following the examples and could not force/reproduce the parallel execution error. Digging into the sources, I found that the default UseDbContext attribute that's coming with the EntityFramework package forwards to a built-in extension method for IObjectFieldDescriptor that's basically already doing the same thing like the manually implemented logic in session 3, doesn't it?

Am I correct that this separate implementation on the application level is not necessary anymore?

MisterGoodcat avatar Sep 01 '21 09:09 MisterGoodcat

Any update on this?

One use case I found for using a custom attribute is when you want to dynamically configure something on the DbContext after creation that cannot be achieved in the global configure hook. For example, if you want to dynamically change the connection string/database user based on the situation, this approach provides a good hook to do that.

Otherwise my above judgement stands, what is described in the workshop does not seem to be required for any default scenario, and could be skipped safely.

MisterGoodcat avatar Oct 07 '21 09:10 MisterGoodcat

We are revamping the workshop at the moment for version 12.

michaelstaib avatar Oct 07 '21 09:10 michaelstaib

https://github.com/ChilliCream/graphql-workshop/tree/master/code/complete/GraphQL

looked at this complete example... its the current draft for the new workshop.

michaelstaib avatar Oct 07 '21 09:10 michaelstaib

We are still working on it .... so its not final yet :)

michaelstaib avatar Oct 07 '21 09:10 michaelstaib