title: Is it possible to instantiate a class which contains an injected enum
body: <p>Is it possible using <code>Microsoft</code>'s DI to <code>inject</code> an <code>enum</code>?</p>
  
  <p>I am getting the following exception when instantiating a class which contains a <code>enum</code> in the <code>constructor</code>.</p>
  
  <blockquote>
    <p>InvalidOperationException: 
            Unable to resolve service for type DependencyInjectionWithEnum.Domain.Types.TestType
            while attempting to activate DependencyInjectionWithEnum.Domain.Service.TestService
        Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, bool throwIfCallSiteNotFound)</p>
  </blockquote>
  
  <p>I have the following enum:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// This is a test enum which is injected into the TestService's constructor
  /// &lt;/summary&gt;
  public enum TestType
  {
      First,
      Second,
      Third,
      Forth,
      Fifth
  }
  </code></pre>
  
  <p>Which gets injected into the following <code></code></p>
  
  <pre><code>public class TestService
  {
      private readonly TestType testType;
  
      /// &lt;summary&gt;
      /// Here I am injecting an enum called TestType
      /// &lt;/summary&gt;
      /// &lt;param name="testType"&gt;&lt;/param&gt;
      public TestService(TestType testType)
      {
          this.testType = testType;
      }
  
      /// &lt;summary&gt;
      /// This is a dummy method.
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public string RunTest()
      {
          switch(testType.ToString().ToUpperInvariant())
          {
              case "First":
                  return "FIRST";
              case "Second":
                  return "SECOND";
              case "Third":
                  return "THIRD";
              case "Forth":
                  return "FORTH";
              case "Fifth":
                  return "FIFTH";
              default:
                  throw new InvalidOperationException();
          }
      }
  }
  </code></pre>
  
  <p>Then in Startup.cs I add the TestService to the ServiceCollection</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      //mvc service
      services.AddMvc();
  
      // Setup the DI for the TestService
      services.AddTransient(typeof(TestService), typeof(TestService));
  
      //data mapper profiler setting
      Mapper.Initialize((config) =&gt;
      {
          config.AddProfile&lt;MappingProfile&gt;();
      });
  
      //Swagger API documentation
      services.AddSwaggerGen(c =&gt;
      {
          c.SwaggerDoc("v1", new Info { Title = "DependencyInjectionWithEnum 
   API", Version = "v1" });
      });
  }
  </code></pre>
  
  <p>Finally I inject my TestService into my controller</p>
  
  <pre><code>[Route("api/[controller]")]
  public class TestController : ControllerBase
  {
      private readonly TestService testService;
  
      /// &lt;summary&gt;
      /// Here I am injecting a TestService. The TestService is the class from which I am attempting to inject an enum
      /// &lt;/summary&gt;
      /// &lt;param name="testService"&gt;&lt;/param&gt;
      public TestController(TestService testService)
      {
          this.testService = testService;
      }
  
      /// &lt;summary&gt;
      /// Dummy get
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      [HttpGet]
      [ProducesResponseType(200, Type = typeof(string))]
      public IActionResult Get()
      {
          var testResult = testService.RunTest();
  
          return Ok(testResult);
      }
  }
  </code></pre>
  
  <p>I get the <code>exception</code> when attempting to call the <code>controller</code>'s endpoint via <code>Swagger</code>.</p>
  
  <p><strong>Tech Stack</strong></p>
  
  <pre><code>- Visual Studio v15.9.4 C# v7.3
   - Project Target Framework .NET Core 2.2
   - NuGet Packages 
     -        Microsoft.AspNetCore v2.2.0
     -        Microsoft.AspNetCore.Mvc v2.2.0
     -        Microsoft.Extensions.DependencyInjection v2.2.0
  </code></pre>