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

HttpClient services using AddHttpClient #9553

Closed
wants to merge 5 commits into from
Closed

HttpClient services using AddHttpClient #9553

wants to merge 5 commits into from

Conversation

fileman
Copy link
Contributor

@fileman fileman commented Jul 9, 2021

When I tried to use the Syncfusion SfDataManager control, I have found that a little change is required to solve URI exception, but I don't know if this break something else in ABP Framework.

If is ok, I will update even the tiered template.

#8259

When I tried to use the Syncfusion SfDataManager control, I have found that a little change is required to solve URI exception, but I don't know if this break something else in ABP Framework.

If is ok, I will update even the tiered template.
@fileman fileman marked this pull request as ready for review July 9, 2021 09:50
@berkansasmaz berkansasmaz added this to the 5.0-preview milestone Jul 9, 2021
@hikalkan hikalkan requested review from maliming and removed request for hikalkan September 16, 2021 08:45
@maliming
Copy link
Member

hi @fileman

Can you complete the PR?

@@ -206,9 +206,9 @@ private void ConfigureSwaggerServices(IServiceCollection services)

private static void ConfigureHttpClient(ServiceConfigurationContext context)
{
context.Services.AddTransient(sp => new HttpClient
context.Services.AddHttpClient("abp", sp =>
Copy link
Member

@maliming maliming Sep 20, 2021

Choose a reason for hiding this comment

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

You can consider using constant string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, you mean something defined in MyProjectNameConsts like DbTablePrefix or inside Blazor/Blazor.Server, since is required only in this UI version?

Copy link
Member

Choose a reason for hiding this comment

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

Can you share the document that explains the AddHttpClient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

When I tried to use the Syncfusion SfDataManager control, I have found that a little change is required to solve URI exception,

Hi

Does Syncfusion have a document explain it?

Can you share the exception details?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have any Syncfusion document for this problem, I found the solution myself by following Microsoft's recommendations for httpclient.

I attached sample to reproduce the following exception "System.UriFormatException: 'Invalid URI: The format of the URI could not be determined.'"
SfDataManager.Server.zip

@totpero
Copy link
Contributor

totpero commented Oct 22, 2021

Hi,
I try to inject "HttpClient" in my page like this:
[Inject] protected HttpClient Http { get; set; }
or in blazor view:
@inject HttpClient Http
with the old configuration context.Services.AddTransient and with the new context.Services.AddHttpClient("abp", sp => .
When I try to call WebApi Endpoint, using : var result = await Http.GetStringAsync("/api/...."); the BaseAddress remains null.
After a few searches I discovered that in ServiceConfigurationContext.Services are more then one service of type HttpClient.

My scope was different so I hard-coded the BaseAddress I have discovered that cookies were not set even if I was logged in the page.
Is there any method to automatically use HttpClient request authorized without calling "/api/account/login" endpoint?

@maliming maliming closed this Oct 23, 2021
@maliming
Copy link
Member

#10405

@fileman
Copy link
Contributor Author

fileman commented Oct 23, 2021

Yes it's not required for "server" so it can be removed.
This could be usefull for someone else as a community post, I'll try to write and submit.

@totpero
Copy link
Contributor

totpero commented Oct 23, 2021

Hi,
HttpClient is already injected into services from other modules. Even if you remove configurehttpclient method, the HttpClient still exists into services with BaseAdress set to null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants