title: How to calling another rest API controller that stores information directly from inside another rest API controller?
body: <p>How would I go about modifying existing code to call other controllers stored dictionary information? (without recalling the db multiple times, but just once at the start of the rest api's life).</p>
  
  <p>Atm (I think) am storing the information in a dictionary (PipeMaterials) correctly. Now I'm lost on how to go about getting the information out to other controller.</p>
  
  <p><a href="https://i.stack.imgur.com/SxTAb.png" rel="nofollow noreferrer">Controller storing information</a> </p>
  
  <p><a href="https://i.stack.imgur.com/XCzub.png" rel="nofollow noreferrer">Controller wanting to consume information</a></p>
  
  <p>Storing</p>
  
  <pre><code>public class MaterialsController : ControllerBase
  {
      public Dictionary&lt;int, Materials&gt; PipeMaterials;
      public Dictionary&lt;int, Rank&gt; Ranks;
      public Dictionary&lt;int, Sumps&gt; Sumps;
  
      private readonly UMMClient23Context _context;
  
      public MaterialsController(UMMClient23Context context)
      {
          _context = context;
          LoadMaterials();
      }
  
      public void LoadMaterials()
      {
          PipeMaterials = new Dictionary&lt;int, Materials&gt;();
          Task&lt;MaterialsObjects&gt; task = GetMaterials();
          var result = task.Result;
          foreach (var item in result.Ummmaterials)
          {
              if (!PipeMaterials.TryAdd(item.MaterialsId, item))
              {
                  Console.Error.WriteLine("Could not load material: " + item.MaterialsName);
              }
          }
      }
  
      // GET: api/Materials
      [HttpGet]
      public async Task&lt;MaterialsObjects&gt; GetMaterials()
      {
          MaterialsObjects returnable = new MaterialsObjects();
          returnable.Ummmaterials = await _context.Materials.ToListAsync();
          return returnable;
      }
  
      // GET: api/MaterialDescription/5
      [HttpGet("{materialsId}")]
      public string GetMaterialDescription(int materialsId)
      {
          Materials item;
          if (PipeMaterials.TryGetValue(materialsId, out item))
          {
              return item.MaterialsName;
          }
          else
          {
              return null;
          }
          //var materials = _context.Materials
          //    .Where(m=&gt; m.MaterialsId == materialsId)
          //    .Select(m =&gt; m.MaterialsName)
          //    .FirstOrDefault();
  
      }
  </code></pre>
  
  <p>Consuming</p>
  
  <pre><code>public class PipeController : ControllerBase
  {
      MaterialsController materialsController;
  
      UMMDBHelper uMMDBHelper;
      private readonly UMMClient23Context _context;
  
      public PipeController(UMMClient23Context context)
      {
          _context = context;
          uMMDBHelper = new UMMDBHelper(context);
      }
  
      //GET: api/Pipe
      [HttpGet]
      public async Task&lt;ActionResult&lt;IEnumerable&lt;Data&gt;&gt;&gt; Get(string value)
      {
          return await _context.Data.ToListAsync();
      }
  
  
      // GET: api/Pipe/{assestNumber}
      [HttpGet("{assetNumber}")] // Make return into Object
      public PipeListObject GetPipe(string assetNumber)
      {
  
          PipeListObject returnable = new PipeListObject();
          Pipe Pipe = uMMDBHelper.GetPipe(assetNumber);
          returnable.UmmPipes.Add(Pipe); 
          return returnable;
      }
  
  
      //GET: api/PipeMaterial/{materialId}
      [HttpGet("{materialId}")]
      public string GetPipeMaterial(int materialId)
      {
          var desc = materialsController.GetMaterialDescription(materialId);
          return desc;
      }
  </code></pre>