I was trying to impliment the following articale:
What did I miss ?
CodePudding user response:
You're missing that package or assembly name isn't the same as the namespace(s) the code lives in. Although it's often convention that a package named "Foo" will occupy the namespace "Foo" and related namespaces will be something like "Foo.Bar", etc. it's not the only way to do this.
You can find out what namespaces and classes a library makes available to you by using the Object Browser:
- In Visual Studio, select "View"
- Select "Object Browser"
- You will see a list of assemblies that are referenced by your solution
- Scroll down to "Microsoft.Extensions.Http.Polly" and expand it
- You can see that it declares code in 4 namespaces:
- Microsoft.Extensions.DependencyInjection
- Microsoft.Extensions.Http
- Microsoft.Extensions.Internal
- Polly
Clicking on "PollyHttpClientBuilderExtensions" shows the methods made available by the class:
And, as the name suggests, the method signature displayed in the lower pane indicates that the selected method is an extension method on IHttpClientBuilder
, so you have to use it in conjunction with services.AddHttpClient()
. It seems likely that this is the one you want to access in your code. Therefore, you should include the following using
:
using Microsoft.Extensions.DependencyInjection;