/// <summary> /// Returns a named instance of the <see cref="IDeliveryClient"/> wrapped in a caching layer. /// </summary> /// <param name="name">A name of the configuration to be used to instantiate the client.</param> /// <returns>Returns an <see cref="IDeliveryClient"/> instance with the given name.</returns> public IDeliveryClient Get(string name) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (!_cache.TryGetValue(name, out var client)) { client = _innerClientFactory.Get(name); var cacheOptions = _deliveryCacheOptions.Get(name); if (cacheOptions.Name == name) { // Build caching services according to the options IDeliveryCacheManager manager; if (cacheOptions.CacheType == CacheTypeEnum.Memory) { var memoryCache = _serviceProvider.GetService <IMemoryCache>(); manager = new MemoryCacheManager(memoryCache, Options.Create(cacheOptions)); } else { var distributedCache = _serviceProvider.GetService <IDistributedCache>(); manager = new DistributedCacheManager(distributedCache, Options.Create(cacheOptions)); } // Decorate the client with a caching layer client = new DeliveryClientCache(manager, client); _cache.TryAdd(name, client); } } return(client); }
public async Task <int> GetOne() { var client = deliveryClientFactory.Get("client1"); var result = await client.GetItemsAsync(); return(result.Items.Count()); }
public async Task <ActionResult> SampleProjectReady() { var defaultProjectClient = DeliveryClientFactory.Get(); var items = (await defaultProjectClient.GetItemsAsync <object>()).Items; return(Json(items.Count >= await GetRequiredItems())); }
public YourController(IDeliveryClientFactory deliveryClientFactory) { // Creates instances of Delivery clients based on their names client1 = deliveryClientFactory.Get("first_project"); client2 = deliveryClientFactory.Get("second_project"); // Gets content items from both projects // Using the generic <object> produces strongly typed objects based on "system.type" var response1 = await client1.GetItemsAsync <object>(); var response2 = await client2.GetItemsAsync <object>(); // Merges the responses IReadOnlyList <object> items = response1.Items.Concat(response2.Items).ToArray(); }
public IDeliveryClient GetDeliveryClient() { if (_deliveryClient == null) { //var projectId = _configuration.GetValue<string>("DeliveryOptions:ProjectId"); //_deliveryClient = DeliveryClientBuilder.WithProjectId(projectId).WithDeliveryHttpClient(_httpClient).Build(); _deliveryClient = _clientFactory.Get("production"); } return(_deliveryClient); }
public CompanyAddressViewComponent(IDeliveryClientFactory deliveryClientFactory) { DeliveryClient = deliveryClientFactory.Get(); }
public CafesRepository(IDeliveryClientFactory deliveryClientFactory) { DeliveryClient = deliveryClientFactory.Get(); }
public ControllerBase(IDeliveryClientFactory deliveryClientFactory) : this() { _client = deliveryClientFactory.Get(); }