NClient icon indicating copy to clipboard operation
NClient copied to clipboard

Creating custom providers using DI

Open smolchanovsky opened this issue 2 years ago • 2 comments

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());

smolchanovsky avatar Apr 16 '22 16:04 smolchanovsky

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

Kingmidas74 avatar Sep 03 '22 07:09 Kingmidas74

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();
});

smolchanovsky avatar Sep 03 '22 08:09 smolchanovsky