I am using HttpClient (aka Web API client) to consume RESTfull services. Services require session to be established (via login) and then destroyed (via logout) upon each operation. So the call to consume service A looks something like this (pseudocode)
// setup create auth dictionary authDict create authenticationContent using FormUrlEndodeContent(authDict) create cookieContainer create HttpClientHandler... create HttpClient // login await httpClient.PostAsync(LoginUrl, authenticationContent); do error checking // perform Operation A await httpClient.....post...or...get... extract data, process it, tranform it, get a cup of coffee, etc, etc populate OperationAResult // logout await httpClient.GetAsync(LogoutUrl); // return result return OperationAResult My question is, how can I easily reuse setup, login, and logout for different operations? Should I be creating some method that will take in Action<> and if so how do I make sure that operations occur in order?