nclient / NClient

:dizzy: NClient is an automatic type-safe .Net HTTP client that allows you to call web service API methods using annotated interfaces or controllers without boilerplate code.
Apache License 2.0
43 stars 11 forks source link

Creating custom providers using DI #433

Open smolchanovsky opened 2 years ago

smolchanovsky commented 2 years ago

I want to create custom providers using DI. From the client's API side, it should look like this:

services.AddRestNClient<IBasicClientWithMetadata>(host: "http://localhost:5000", 
    implementationFactory: builder => builder
        .WithHandling<MyHandler>()
        .Build());
Kingmidas74 commented 1 year ago

I'm sorry, but this feature already implemented, isn't? https://github.com/nclient/NClient/blob/main/tests/NClient.Extensions/NClient.Extensions.DependencyInjection.Tests/AddRestNClientExtensionsTest.cs#L73

smolchanovsky commented 1 year ago

No, there is no such feature yet. Please note how the handler is created:

.WithHandling<MyHandler>()

Now we can only create a handler like this:

services.AddRestNClient<IBasicClientWithMetadata>(host: "http://localhost:5000", implementationFactory: (serviceProvider, builder) => 
{
    var myHandler = serviceProvider.GetRequiredService<MyHandler>();
    return builder
        .WithHandling(myHandler)
        .Build();
});