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

Adding HostProvider #448

Closed
smolchanovsky opened this issue Jul 19, 2022 · 4 comments · Fixed by #461
Closed

Adding HostProvider #448

smolchanovsky opened this issue Jul 19, 2022 · 4 comments · Fixed by #461
Assignees
Milestone

Comments

@smolchanovsky
Copy link
Member

The HostProvider will allow getting hosts in runtime. Most likely, the provider should be passed to For method.

@Kingmidas74
Copy link
Member

How you suggest use IHostProvider with DI? We should setup host on service.AddNClient(.....)

@smolchanovsky
Copy link
Member Author

I think it can look like this:

serviceCollection.AddRestNClient(implementationFactory: (serviceProvider, builder) =>
{
    var hostProvider = serviceProvider.GetRequiredService<MyHostProvider>();
    builder.For<IMyClient>(hostProvider).Build();
});

@Kingmidas74
Copy link
Member

@smolchanovsky
Copy link
Member Author

Not quite. We can do for example like this:

serviceCollection.AddRestNClient(implementationFactory: (serviceProvider, builder) => 
{
    var hostProvider = serviceProvider.GetRequiredService<MyHostProvider>();
    var host = hostProvider.Get();
    builder
        .For<IBasicClientWithMetadata>(host)
        .Build()
});

This is similar to what I want, but the host provider will create the host only once, since the client is a singleton. Perhaps if we implement #449 (comment), it will cover most of the needs. However, we should remember that clients can be created not only using DI.

@Kingmidas74 Kingmidas74 self-assigned this Sep 11, 2022
This was linked to pull requests Sep 11, 2022
@smolchanovsky smolchanovsky added this to the 0.14.0 milestone Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants