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

.NET Microservices eBook is being updated to .NET Core 2.1 "wave" of technologies! #17

Open
CESARDELATORRE opened this issue Jun 18, 2018 · 11 comments

Comments

@CESARDELATORRE
Copy link
Contributor

CESARDELATORRE commented Jun 18, 2018

The .NET Microservices eBook is being updated to .NET Core 2.1 "wave" of technologies!

Main subjects/chapters updated:

  • HttpClientFactory + Polly for resilient Http communication in .NET Core 2.1
  • API Gateways and implementation with Ocelot
  • Minor updates related to .NET Core 2.1 versions, packages and Docker images

Download from: https://aka.ms/microservicesebook
image

Note that this is still an on-going effort, hence the version "v2.1.01".

In the upcoming weeks it'll be updated in a few more topics and the version will be updated to the next minor versions, such as "v2.1.01", "v2.1.02", etc.

But we think the community appreciates having sooner updates in the guidance instead of a single big update coming later.

@Sn3b
Copy link

Sn3b commented Jun 19, 2018

Great news! Would you please also update the ePub and mobi versions?

@ayayalar
Copy link

ayayalar commented Jun 19, 2018 via email

@maulikk2000
Copy link

maulikk2000 commented Jun 20, 2018 via email

@CESARDELATORRE
Copy link
Contributor Author

@Sn3b @ayayalar - The eReaders (mobi and epub) versions will be updated in the upcoming weeks, ok? :)

@CESARDELATORRE
Copy link
Contributor Author

@maulikk2000 - Is there any reason why you cannot use HttpClientFactory in .NET Core 2.1 for your scenario? - That’s the recommended way to use HttpClient so it re-uses the pool of handlers plus it is easi r to use policies.
If possible, use HttpClientFactory, either with typed clients, named clients or even directly.
Take a look to the section about HttpClientFactory in the eBook and also to the references I put about HttpClientFactory.
If you had issues, tell me so we’ll look for further possibilities, ok? :)

@ayayalar
Copy link

ayayalar commented Jun 20, 2018 via email

@maulikk2000
Copy link

maulikk2000 commented Jun 20, 2018 via email

@onizet
Copy link

onizet commented Jun 20, 2018

var clientBuilder = services.AddHttpClient("openhackAPI", client => { ... });
clientBuilder.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler() {
   ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
});

Btw, I'm curious about your Bearer token and its lifetime (unless this is an offline_token).
I forward the call to another internal server by providing the received bearer token, with the use of a MessageHandler:

var clientBuilder = services.AddHttpClient("openhackAPI", client => { ... })
      .AddHttpMessageHandler<BearerTokenHandler>();

/// <summary>
/// Provides the Bearer authentication header from the current caller.
/// </summary>
sealed class BearerTokenHandler : DelegatingHandler
{
     private readonly IHttpContextAccessor httpContextAccessor;

     public BearerTokenHandler(IHttpContextAccessor httpContextAccessor)
     {
         this.httpContextAccessor = httpContextAccessor;
     }

     protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
         CancellationToken cancellationToken)
     {
         var context = httpContextAccessor.HttpContext;
         if (context.Request.Headers.TryGetValue("Authorization", out StringValues bearer))
             request.Headers.Authorization = AuthenticationHeaderValue.Parse(bearer.ToString());

         return await base.SendAsync(request, cancellationToken);
     }
}

@sashcatk
Copy link

sashcatk commented Jun 20, 2018 via email

@maulikk2000
Copy link

maulikk2000 commented Jun 20, 2018 via email

@CESARDELATORRE
Copy link
Contributor Author

@onizet @maulikk2000 - Right, comment from @onizet about setting the PrimaryHandler is how you must configure HttpClientHandler.

There's some more info here:
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-2.1#configure-the-httpmessagehandler

I told the ASP.NET team that we should have some further documentation bout this topic. 👍

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

No branches or pull requests

6 participants