Skip to content
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

Update middleware sample #2903

Merged
merged 1 commit into from
Feb 3, 2022
Merged

Update middleware sample #2903

merged 1 commit into from
Feb 3, 2022

Conversation

Shane32
Copy link
Member

@Shane32 Shane32 commented Feb 3, 2022

  • Make the middleware a singleton
  • Pulls ISchema via DI
  • Middleware implements ASP.Net IMiddleware interface

@Shane32 Shane32 requested a review from sungam3r February 3, 2022 12:30
@Shane32 Shane32 self-assigned this Feb 3, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #2903 (957a2b4) into master (4eeeef0) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2903   +/-   ##
=======================================
  Coverage   83.77%   83.77%           
=======================================
  Files         366      366           
  Lines       15017    15017           
  Branches     2375     2375           
=======================================
  Hits        12580    12580           
  Misses       1802     1802           
  Partials      635      635           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4eeeef0...957a2b4. Read the comment docs.

@Shane32 Shane32 added the documentation An issue or pull request regarding documentation improvements label Feb 3, 2022
@@ -56,6 +56,7 @@ public void ConfigureServices(IServiceCollection services)
// add infrastructure stuff
services.AddHttpContextAccessor();
services.AddLogging(builder => builder.AddConsole());
services.AddSingleton<GraphQLMiddleware>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did it work before? I mean app.UseMiddleware<GraphQLMiddleware>(); without services.Add?

Copy link
Member

@sungam3r sungam3r Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All services from ctor and Invoke are discovered and pulled by ASP.NET subsystem, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, yes that was correct, as it was "ASP.Net Core convention-based middleware". It was essentially a scoped/transient service, and DI services could be added to either the constructor or Invoke method.

With this change, the middleware is pulled from DI and it is called "ASP.Net Core factory-based middleware".

I think it's just a clearer sample.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about middleware from server repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll review when I look at the serialization

@Shane32 Shane32 merged commit 45f36bb into master Feb 3, 2022
@Shane32 Shane32 deleted the update_middleware_sample branch February 3, 2022 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation An issue or pull request regarding documentation improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants