Comments (4)
@chrismo111 Thanks again for your help! 👍
Will be giving these a try.
from gotenbergsharpapiclient.
TL;DR: Yes, you can configure the client with your retry settings when not using constructor injection in a netcore app .E.G. for use in a static class. Details are further down the thread below.
Question 2:
GotenbergSharpClient was built as a “typed client” for use with dependency injection. I'll make that more clear in the ReadMe. The way the client is written, setting up the Retry Policy requires D.I.
The constructor overloads for string and Uri were added to simplify the LinqPad demo code samples. I should've decorated them with the Obsolete attribute or EditorBrowsable(EditorBrowsableState.Never). The overload that accepts an instance of HttpClient shouldn't be used either (I need to remove the PublicApi attribute from that).
GotenbergSharpClient and its inner HttpClient are created and managed by HttpClientFactory behind the scenes when you call the AddGotenbergSharpClient service collection extension which in turn calls AddHttpClient and AddTypedClient. That extension also sets all the options and wires up the Polly Retry policy.
By adding the options and calling AddGotenbergSharpClient in StartUp.ConfigureServices you'll receive an instance of the client pre-configured with your settings whenever its injected or resolved through a ServiceProvider.
Take a look at these resources that outline all the benefits of DI/HttpClientFactory with Typed Clients:
- 3 ways to use HTTPClientFactory in ASP.NET Core 2.1
- HttpClientFactory in ASP.NET CORE 2.1, Part 1 An Intro
- Part 2, Defining Named & Typed Clients
- Polly and HttpClientFactory
Question 1:
To see the options set after the container is built just resolve them as IOptions through a service provider. E.G. sp.GetRequiredService<IOptions<GotenbergSharpClientOptions>>().Value
You could also get them in Startup like this:
var test = Configuration.GetSection(nameof(GotenbergSharpClient)).Get<GotenbergSharpClientOptions>();
When calling Configuration.GetSection alone the test.Value property is supposed to be null by design. From the MS documentation:
"When GetSection returns a matching section, Value isn't populated. A Key and Path are returned when the section exists."
See a discussion here: https://stackoverflow.com/q/46017593
from gotenbergsharpapiclient.
@chrismo111 Thanks for your reply 👍
Current situation I am in is we are using heavily static classes, project was using WebForms/WCF and ported to .Net Core, but slowly converting those to services that uses DI, but for PDF need to use it now in our static pdf helper for the time being.
So when used in a static class the Retry policy does not kick in then?
Is there a way to use a service locator in static class to get it to work?
Also still have
Question 4:
What is the best way to Unit test Gotenberg Server Errors which results in HttpResonse errors, to trigger the retry policy to kick in?
I also need to create Unit test that would cause the Retry to trigger.
Thanks again 👍
from gotenbergsharpapiclient.
If you're willing to use a service locator that'll work.
You'll still need to add the options and call services.AddGotenbergSharpClient to have your settings applied. When the service locator resolves an instance it'll be configured with those settings.
YMMV but I whipped together a little proof of concept where everything worked, including retries, in both netcore app2 and 3x. My service locator was based on this example.
Within a static class you'll be able to retrieve the client like this:
var sharpClient = ServiceLocator.ServiceProvider.GetService<GotenbergSharpClient>();
Testing the retry policy?
See Unit Test and Mock Typed HttpClient using HttpClientFactory .NET Core
I'd also start by looking at how Polly Tests them & their documentation:
from gotenbergsharpapiclient.
Related Issues (18)
- Add this library in the "official" documentation HOT 2
- Gotenberg 6.1.0 HOT 1
- Compatibility with netcoreapp2.2 HOT 1
- Gotenberg 6.2.0 HOT 4
- Parsing error on demensions parse float issue HOT 2
- Error handling HOT 2
- Dimensions.cs ToHttpContent() breaks numeric values due to unawareness of globalization HOT 2
- Release v1.1.0
- New version of Gotenberg 🚀 HOT 11
- No emulatedMediaType option for v7 HOT 4
- Container returns "Not Found" for all endpoints HOT 3
- Convert single office file to pdf HOT 3
- Can we post byte array office file to get byte array pdf? HOT 2
- Breaking change in .NET 6 causes this client to throw exception because of Globalization issues HOT 2
- Support for trace HOT 2
- An item with the same key has already been added. Key: Gotenberg-Webhook-Extra-Http-Headers HOT 2
- how to set title to pdf? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gotenbergsharpapiclient.