title: How to call a custom service at startup with dependencies in dotnet core 3?
body: <p>I created a dotnet core MVC app. When the app starts the first time, I want to load some data from the database to a in-memory cache.</p>
  
  <p>I know how to use the IMemoryCache, to fill data inside and to get them.
  However, when the app start, I want to fill the in-memory cache with the data from the database. So I created a Singleton called ReferenceCache and the Interface IReferenceCache.</p>
  
  <pre><code>public interface IReferenceCache
  {
      public void Setup(IMemoryCache cache);
  }
  
  public class ReferenceCache : IReferenceCache
  {
      private ILogger&lt;ReferenceCache&gt; _logger;
      private IMemoryCache _cache;
  
      public void Setup(IMemoryCache cache)
      {
          //_logger = logger;
          _cache = cache;
          using (var context = new UtpmvContext())
          {
              var references = context.Reference.ToList();
              _cache.Set("reference", references);
          }
      }
  
      public List&lt;Reference&gt; GetSomeData()
      {
          var lsReferences = _cache.Get&lt;List&lt;Reference&gt;&gt;("reference");
          List&lt;Reference&gt; liste = lsReferences.FindAll(x =&gt; x.ReferenceId == "ANY_ID");
          return liste;
      }
  }
  </code></pre>
  
  <p>In the ConfigureServices I added my singleton:</p>
  
  <pre><code>services.AddSingleton&lt;IReferenceCache, ReferenceCache&gt;();
  </code></pre>
  
  <p>Then in the Configure section of the startup file, I added IReferenceCache and IMemoryCache in the signature and call my setup class.</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IReferenceCache cache, IMemoryCache memoryCache)
      {
          // ... code removed for clarity
          // I call my service to load the data in the in-memory 
          cache.Setup(memoryCache);
      }
  </code></pre>
  
  <p>The thing is in my ReferenceCache class, I want to be able to log... so how can I add a dependency of ILogger?</p>
  
  <p>I have never created any service in dotnet core before so please let me know if my design is not correct.</p>
  
  <p>Thank you for your help! :)</p>