title: Caching does not exist in namespace Microsoft.Extensions
body: <p>I am moving some logic from a micro service to a azure function.</p>
  
  <p>Things are going pretty smoothly, however I have run into a dependency issue. I had some caching features in the micro service that I would like to keep in the azure function, however the function project will not build because it cannot resolve <code>Microsoft.Extensions.Caching.Memory</code> namespace.</p>
  
  <p>I installed <code>Microsoft.Extensions.DependencyInjection</code> via nuget in the new function project so that I could use DI in this function app. I think this is the reason why <code>Microsoft.Extensions.Caching</code> is no longer resolving. </p>
  
  <p>The error is the common: <code>The type or namespace 'Caching' does not exist in the namespace 'Microsoft.Extensions'</code></p>
  
  <p>Shouldn't they both be exposed under Microsoft.Extensions namespace?
  Does anyone have any idea how to resolve this?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT:</strong> Some code samples. </p>
  
  <p>Function Code:
  (DI setup is almost exactly <a href="https://blog.wille-zone.de/post/azure-functions-dependency-injection/" rel="nofollow noreferrer">this</a>)</p>
  
  <pre><code>using Microsoft.AspNetCore.Mvc;
  using Microsoft.Azure.WebJobs;
  using Microsoft.Azure.WebJobs.Extensions.Http;
  using Microsoft.AspNetCore.Http;
  using Microsoft.Azure.WebJobs.Host;
  using PI.Warehouses.API.Repositories;
  using ESPIWarehouseFunction.Injection;
  
  namespace ESPIWarehouseFunction
  {
      public static class WarehouseFunctions
      {
  
          [FunctionName("GetAll")]
          public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req, 
              TraceWriter log, [Inject(typeof(IWarehouseStateRepository))]IWarehouseStateRepository repoW)
          {
              log.Info("GetAll Function is processing a request");
              var warehouses = repoW.GetAllWarehouses();
              return warehouses != null ? 
                  (ActionResult)new OkObjectResult(warehouses) :
                  new BadRequestObjectResult("Something went wrong with this request");
          }
      }
  }
  </code></pre>
  
  <p>One of many code pieces that uses the cache:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;
  using System.Threading;
  using MediatR;
  using PI.Warehouses.Domain.Aggregate.Commands;
  using PI.Warehouses.Domain.Aggregate.Events;
  using PI.Warehouses.Domain.Model;
  using PI.Warehouses.API.Repositories;
  using Newtonsoft.Json;
  using PI.Warehouses.Domain.Aggregate.Exceptions;
  using Microsoft.Extensions.Caching.Memory;
  
  namespace PI.Warehouses.API.Application.Handlers.Commands
  {
      public class AddMaterialHandler : IRequestHandler&lt;AddMaterialCommand, EventList&gt;
      {
          private readonly IEventRepository _repoEvents;
          private readonly IWarehouseStateRepository _repoWarehouse;
          private readonly IMediator _mediator;
          private IMemoryCache _cache;
          private EventList _eventsCreated;
  
          public AddMaterialHandler(IEventRepository repoE, IWarehouseStateRepository repoW, IMediator mediator, IMemoryCache cache)
          {
              _repoEvents = repoE;
              _repoWarehouse = repoW;
              _mediator = mediator;
              _cache = cache;
              _eventsCreated = new EventList();
          }
  
              // some setups stuffs ...
  
              WarehouseState state;
              if (!_cache.TryGetValue(cmd.WarehouseId, out WarehouseState cachedState))
                  state = await _repoWarehouse.GetWarehouseState(cmd.WarehouseId);
              else
                  state = new WarehouseState(cachedState);
  
  
              // Rest of this handler
      }
  }
  </code></pre>