OData / Extensions

ExtensionsLib: - Extensions for OData libraries and framework
MIT License
11 stars 19 forks source link

Allow access to service provider on ConfigureODataClient #28

Open weitzhandler opened 4 years ago

weitzhandler commented 4 years ago

Hi,

I have a tenant app that has various services that provide information about the current tenant, user, and the URLs to be used to access server resources, per tenant/user. It's called IUriProvider.

I can see the method in DefaultODataClientFactory based on serviceRoot. But I rather them all to be based on the underlying IHttpClientFactory's provided HttpClient.BaseAddress.

In addition, the IOdataClientFactory.CreateClient<T>, also requires a serviceRoot argument. This is unnecessary if it has already been configured, or if there is an underlying HttpClient whose BaseAddress should be used for this matter instead. Asking for Uris all over the place which would rely on constants, is a bad habit and somewhat defies the power of DI.

weitzhandler commented 4 years ago

This code:

public class PeopleController : ODataController
{
    private readonly IODataClientFactory _clientFactory;

    public PeopleController(IODataClientFactory clientFactory)
    {
        _clientFactory = clientFactory;
    }

    [EnableQuery]
    public IEnumerable<Person> Get()
    {
        var client = _clientFactory.CreateClient<DefaultContainer>();
        var people = client.People.Execute();
        return people;
    }
}

Does not work. There is no overload of CreateClient that can take care of the serviceUri parameters on its own. Please address this.

dotdiego commented 3 years ago

Hello,

Has this problem been adressed ?

We can see that in the documentation https://docs.microsoft.com/en-us/odata/client/using-extensions#named-clients

You allow configuration of the CreateClient within the Startup.cs but no constructor exists for CreateClient that takes no parameter

Schoof-T commented 2 years ago

How has this not been resolved yet? This seems like such a strange oversight, how does everyone else work around this?

erizet commented 1 year ago

I have the same question too. Any new input?

se-andbjo commented 1 year ago

I'm facing the same issue, any news on this?