Handling of AddHttpClient in SDK developmentAndroid SDK installation doesn't find JDKAndroid SDK Manager Not Installing ComponentsError Handling on Java SDK for REST API serviceCan I delete private declarations from headers in possible SDK?Automatically accept all SDK licencesHow to add own claims after logging in to Azure AD with OIDC in ASP.NET Core 2 with dependency injection?Is it OK to pass DI Contantainer as a dependency through a long chain of classes if only last class needs it exactly?IdentityServer 4. Invalid operation Exception in MVC Client of IClientStoreHttpClientFactory response times taking increasingly longerAdd digest authentiacation to a client built by IHttpFactory

How to model a twisted cylinder like this

Silly doubt about tidal effects and Einstein Field Equations

Is "Busen" just the area between the breasts?

How do I handle a table mixing up the DM and the players' roles too often?

Array initialization optimization

How is hair tissue mineral analysis performed?

Cut the gold chain

Greeting with "Ho"

Employer wants to use my work email account after I quit

Loss of power when I remove item from the outlet

What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?

Why does Linux list NVMe drives as /dev/nvme0 instead of /dev/sda?

Why are < or > required to use /dev/tcp

Interaction between Leyline of Anticipation and Teferi, Time Raveler

Trainee keeps missing deadlines for independent learning

How to remove this component from PCB

Heavily limited premature compiler translates text into excecutable python code

When two first person POV characters meet

What could exist inside and between the walls of a Dyson Sphere?

How did Bellatrix know about the Philosopher's Stone?

Can humans ever directly see a few photons at a time? Can a human see a single photon?

Does having had a visa for a country mean I used to be a citizen/national of that country?

Do I need a shock-proof watch for cycling?

Find the C-factor of a vote



Handling of AddHttpClient in SDK development


Android SDK installation doesn't find JDKAndroid SDK Manager Not Installing ComponentsError Handling on Java SDK for REST API serviceCan I delete private declarations from headers in possible SDK?Automatically accept all SDK licencesHow to add own claims after logging in to Azure AD with OIDC in ASP.NET Core 2 with dependency injection?Is it OK to pass DI Contantainer as a dependency through a long chain of classes if only last class needs it exactly?IdentityServer 4. Invalid operation Exception in MVC Client of IClientStoreHttpClientFactory response times taking increasingly longerAdd digest authentiacation to a client built by IHttpFactory






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am developing a .NET Core SDK for our client. The SDK is using the IHttpClientFactory to create a HttpClient for usage in its various methods. I am now writing a custom ServiceCollection Extension, in line with many other SDKs, that will setup my classes configuration.



 public static class ServiceCollectionExtensions

public static IServiceCollection AddMyApi(this IServiceCollection serviceCollection,
Action<MyApiOptions> setupAction)

Check.NotNull(serviceCollection, (nameof(serviceCollection)));
Check.NotNull(setupAction, (nameof(setupAction)));

serviceCollection.Configure(setupAction);

return AddMyApi(serviceCollection);


public static IServiceCollection AddMyApi(this IServiceCollection serviceCollection,
IConfiguration configuration)

Check.NotNull(serviceCollection, (nameof(serviceCollection)));
Check.NotNull(configuration, (nameof(configuration)));

serviceCollection.Configure<MyApiOptions>(configuration);

return AddMyApi(serviceCollection);


private static IServiceCollection AddMyApi(this IServiceCollection serviceCollection)

return serviceCollection
.AddTransient<IMyApiClient, MyApiClient>(sp => new MyApiClient(sp.GetRequiredService<IHttpClientFactory>(), sp.GetRequiredService<ILogger<MyApiClient>>()))
.AddTransient(sp => new MyApi(sp.GetRequiredService<IOptions<MyApiOptions>>(), sp.GetRequiredService<IMyApiClient>()));




This however requires that the client has already called AddLogging() and AddHttpClient() extension methods. Whats the common way of implementing and handling this in your own SDK?



I kinda want to be able to handle both scenarios.










share|improve this question






















  • By calling those dependent extensions yourself if they have not already been called. check the service collection for you dependent types and if not present then add them.

    – Nkosi
    Mar 25 at 12:33


















0















I am developing a .NET Core SDK for our client. The SDK is using the IHttpClientFactory to create a HttpClient for usage in its various methods. I am now writing a custom ServiceCollection Extension, in line with many other SDKs, that will setup my classes configuration.



 public static class ServiceCollectionExtensions

public static IServiceCollection AddMyApi(this IServiceCollection serviceCollection,
Action<MyApiOptions> setupAction)

Check.NotNull(serviceCollection, (nameof(serviceCollection)));
Check.NotNull(setupAction, (nameof(setupAction)));

serviceCollection.Configure(setupAction);

return AddMyApi(serviceCollection);


public static IServiceCollection AddMyApi(this IServiceCollection serviceCollection,
IConfiguration configuration)

Check.NotNull(serviceCollection, (nameof(serviceCollection)));
Check.NotNull(configuration, (nameof(configuration)));

serviceCollection.Configure<MyApiOptions>(configuration);

return AddMyApi(serviceCollection);


private static IServiceCollection AddMyApi(this IServiceCollection serviceCollection)

return serviceCollection
.AddTransient<IMyApiClient, MyApiClient>(sp => new MyApiClient(sp.GetRequiredService<IHttpClientFactory>(), sp.GetRequiredService<ILogger<MyApiClient>>()))
.AddTransient(sp => new MyApi(sp.GetRequiredService<IOptions<MyApiOptions>>(), sp.GetRequiredService<IMyApiClient>()));




This however requires that the client has already called AddLogging() and AddHttpClient() extension methods. Whats the common way of implementing and handling this in your own SDK?



I kinda want to be able to handle both scenarios.










share|improve this question






















  • By calling those dependent extensions yourself if they have not already been called. check the service collection for you dependent types and if not present then add them.

    – Nkosi
    Mar 25 at 12:33














0












0








0


0






I am developing a .NET Core SDK for our client. The SDK is using the IHttpClientFactory to create a HttpClient for usage in its various methods. I am now writing a custom ServiceCollection Extension, in line with many other SDKs, that will setup my classes configuration.



 public static class ServiceCollectionExtensions

public static IServiceCollection AddMyApi(this IServiceCollection serviceCollection,
Action<MyApiOptions> setupAction)

Check.NotNull(serviceCollection, (nameof(serviceCollection)));
Check.NotNull(setupAction, (nameof(setupAction)));

serviceCollection.Configure(setupAction);

return AddMyApi(serviceCollection);


public static IServiceCollection AddMyApi(this IServiceCollection serviceCollection,
IConfiguration configuration)

Check.NotNull(serviceCollection, (nameof(serviceCollection)));
Check.NotNull(configuration, (nameof(configuration)));

serviceCollection.Configure<MyApiOptions>(configuration);

return AddMyApi(serviceCollection);


private static IServiceCollection AddMyApi(this IServiceCollection serviceCollection)

return serviceCollection
.AddTransient<IMyApiClient, MyApiClient>(sp => new MyApiClient(sp.GetRequiredService<IHttpClientFactory>(), sp.GetRequiredService<ILogger<MyApiClient>>()))
.AddTransient(sp => new MyApi(sp.GetRequiredService<IOptions<MyApiOptions>>(), sp.GetRequiredService<IMyApiClient>()));




This however requires that the client has already called AddLogging() and AddHttpClient() extension methods. Whats the common way of implementing and handling this in your own SDK?



I kinda want to be able to handle both scenarios.










share|improve this question














I am developing a .NET Core SDK for our client. The SDK is using the IHttpClientFactory to create a HttpClient for usage in its various methods. I am now writing a custom ServiceCollection Extension, in line with many other SDKs, that will setup my classes configuration.



 public static class ServiceCollectionExtensions

public static IServiceCollection AddMyApi(this IServiceCollection serviceCollection,
Action<MyApiOptions> setupAction)

Check.NotNull(serviceCollection, (nameof(serviceCollection)));
Check.NotNull(setupAction, (nameof(setupAction)));

serviceCollection.Configure(setupAction);

return AddMyApi(serviceCollection);


public static IServiceCollection AddMyApi(this IServiceCollection serviceCollection,
IConfiguration configuration)

Check.NotNull(serviceCollection, (nameof(serviceCollection)));
Check.NotNull(configuration, (nameof(configuration)));

serviceCollection.Configure<MyApiOptions>(configuration);

return AddMyApi(serviceCollection);


private static IServiceCollection AddMyApi(this IServiceCollection serviceCollection)

return serviceCollection
.AddTransient<IMyApiClient, MyApiClient>(sp => new MyApiClient(sp.GetRequiredService<IHttpClientFactory>(), sp.GetRequiredService<ILogger<MyApiClient>>()))
.AddTransient(sp => new MyApi(sp.GetRequiredService<IOptions<MyApiOptions>>(), sp.GetRequiredService<IMyApiClient>()));




This however requires that the client has already called AddLogging() and AddHttpClient() extension methods. Whats the common way of implementing and handling this in your own SDK?



I kinda want to be able to handle both scenarios.







dependency-injection .net-core sdk httpclientfactory






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 8:35









UrbanEscUrbanEsc

3,13013562




3,13013562












  • By calling those dependent extensions yourself if they have not already been called. check the service collection for you dependent types and if not present then add them.

    – Nkosi
    Mar 25 at 12:33


















  • By calling those dependent extensions yourself if they have not already been called. check the service collection for you dependent types and if not present then add them.

    – Nkosi
    Mar 25 at 12:33

















By calling those dependent extensions yourself if they have not already been called. check the service collection for you dependent types and if not present then add them.

– Nkosi
Mar 25 at 12:33






By calling those dependent extensions yourself if they have not already been called. check the service collection for you dependent types and if not present then add them.

– Nkosi
Mar 25 at 12:33













0






active

oldest

votes














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333869%2fhandling-of-addhttpclient-in-sdk-development%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333869%2fhandling-of-addhttpclient-in-sdk-development%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript