title: Use the ActivatorUtilities to determine which implementation to inject at runtime
body: <p>I am using the built in .Net Core IoC container to resolve the application's dependencies. The way I have configured it is as follows with the use of Scrutor to scan my assembly:</p>
  
  <pre><code>services.Scan(s =&gt; s
      .FromAssembliesOf(currentAssemblyTypesList)
      .AddClasses(false)
      .UsingRegistrationStrategy(RegistrationStrategy.Append)
      .AsImplementedInterfaces()
      .WithTransientLifetime());
  </code></pre>
  
  <p>Up until now I've had simple cases in which each interface is implemented by one dependency so the previous configuration works perfectly to resolve the whole dependency tree. </p>
  
  <p>Now consider the following code:</p>
  
  <pre><code>public interface IService {}  
  
  public class ServiceOne : IService 
  {
       public ServiceOne(IDependency dependency) {}
  }  
  
  public class ServiceTwo : IService 
  {
       public ServiceTwo(IDependency dependency) {}
  }  
  
  public class SomeClass  
  {  
      public SomeClass(IService service) {}  
  
      public void DoSomething()
      {
          this.service.SomeMethod();
      }
  }
  </code></pre>
  
  <p>In this case "SomeClass" is in the middle of a dependency tree and I have two services that implement the same interface and which one should be injected into "SomeClass" will not be known until runtime. For reasons unimportant I have been asked that I should use the ActivatorUtilities class for this.</p>
  
  <p>I am dealing with two scenarios for determining which IService should be instantiated:</p>
  
  <ol>
  <li>At application startup a flag gets set that determines which service is to be used before the registration takes place (for a similar setup but NOT for the same dependency tree).</li>
  <li>During the execution of the "DoSomething" method a decision is made for which one of the two services should be used so I'm guessing some kind of factory should be registered and injected to "SomeClass".</li>
  </ol>
  
  <p>So the question is what do I need to change or add to the dependency registration process and how do I use the ActivatorUtilities class to accomplish these objectives?</p>
  
  <p>Thank you.</p>