public SessionFactoryConfiguration BuildFactoryConfiguration() { // load all the models var modelScanner = new ModelScanner(); foreach (var scan in ModelScannners) { scan(modelScanner); } var jsonSettings = new JsonSerializerSettings(); foreach (var settings in SerializerSettings) { settings(jsonSettings); } var bundledHttpRequestModifiers = new BundledHttpRequestModifier(HttpRequestModifiers); var bundledHttpResponseListeners = new BundledHttpResponseListener(HttpResponseListeners); // translate model attributes to session config modelScanner.Configure(SessionFactoryConfiguration); SessionFactoryConfiguration.Configure(jsonSettings); SessionFactoryConfiguration.Configure(bundledHttpRequestModifiers); SessionFactoryConfiguration.Configure(bundledHttpResponseListeners); ClientConfigurators.Add(client => client.BaseAddress = ApiHost); var builder = new HttpClientBuilder(); (HttpClientBuilder ?? (_ => { }))(builder); // build HttpClient factory SessionFactoryConfiguration.HttpClientFactory = () => { var client = new HttpClient(builder.Build()); client .DefaultRequestHeaders .Accept .Add(MediaTypeWithQualityHeaderValue.Parse("application/vnd.api+json")); foreach (var configure in ClientConfigurators) { configure(client); } Task.WaitAll(AsyncClientConfigurators.Select(x => x.Invoke(client)).ToArray()); return(client); }; return(SessionFactoryConfiguration); }
internal SessionFactory( Func <HttpClient> httpClientFactory, IEnumerable <ModelConfiguration> modelConfigurations, JsonSerializerSettings jsonSettings, HttpRequestModifier httpRequestModifier, BundledHttpResponseListener httpResponseListener) { HttpClientFactory = httpClientFactory; ModelConfigurations = modelConfigurations; JsonSettings = jsonSettings; HttpRequestModifier = httpRequestModifier; HttpResponseListener = httpResponseListener; }
internal Session( Func <HttpClient> httpClientFactory, IHttpRequestBuilder httpRequestBuilder, ICacheProvider cache, IModelRegistry modelRegistry, JsonSerializerSettings jsonSettings, BundledHttpResponseListener httpResponseListener) { HttpClient = httpClientFactory(); HttpRequestBuilder = httpRequestBuilder; Cache = cache; ModelRegistry = modelRegistry; JsonSettings = jsonSettings; HttpResponseListener = httpResponseListener; JsonDiff = new JsonDiff(); JsonComparer = new LooseJsonEqualityComparer(); }
internal void Configure(BundledHttpResponseListener httpResponseListener) { HttpResponseListener = httpResponseListener; }