title: Autofac list of types that implements interface / C# Asp.net
body: <p>I had the problem with Autofac and memory leak in NServiceBus Scheduler. But fortunately I fixed that. </p>
  
  <p><a href="https://stackoverflow.com/questions/50611670/autofac-and-memory-leak-with-beginlifetimescope-dbcontext-has-been-disposed">Autofac and memory leak with BeginLifetimeScope / DbContext has been disposed / C# asp.net</a></p>
  
  <p>But now I'm trying to refactor this part slightly. </p>
  
  <p>My code:</p>
  
  <pre><code>public void Start()
  {
      List&lt;Type&gt; jobTypes = new List&lt;Type&gt; { typeof(ExpiryDateTask) };
  
      foreach (var jobType in jobTypes)
      {
          _schedule.Every(TimeSpan.FromSeconds(30), () =&gt;
          {
              using (var scope = _lifetimeScope.BeginLifetimeScope())
              {
                  var job = scope.Resolve&lt;IJob&gt;();
                  job.Run();
              }
          });
      }
  }
  </code></pre>
  
  <p>How can I refactor this part:</p>
  
  <ol>
  <li><code>List&lt;Type&gt; jobTypes = new List&lt;Type&gt; { typeof(ExpiryDateTask) };</code> -
  that list should be filled somehow by all Types of Tasks that implement
  IJob interface.</li>
  <li><code>var job = scope.Resolve&lt;IJob&gt;();</code> I think this is wrong and should looks more like <code>var job = resolveJob(jobType)</code> - so basically based on the type. </li>
  </ol>
  
  <hr>
  
  <p>@EDIT</p>
  
  <p>Point (1) solved by <a href="https://stackoverflow.com/questions/26733/getting-all-types-that-implement-an-interface">Getting all types that implement an interface</a></p>