title: Unable to resolve service for type while attempting to activate
body: <p>In my ASP.NET Core application, I get the following error:</p>
  <blockquote>
  <p>InvalidOperationException: Unable to resolve service for type 'Cities.Models.IRepository' while attempting to activate 'Cities.Controllers.HomeController'.</p>
  </blockquote>
  <p>I the <code>HomeController</code> I am trying to pass the <code>Cities</code> getter to the view like so:</p>
  <pre class="lang-cs prettyprint-override"><code>public class HomeController : Controller
  {
      private readonly IRepository repository;
  
      public HomeController(IRepository repo) =&gt; repository = repo;
  
      public IActionResult Index() =&gt; View(repository.Cities);
  }
  </code></pre>
  <p>I have one file <code>Repository.cs</code> that contains an interface and its implementation like so:</p>
  <pre class="lang-cs prettyprint-override"><code>public interface IRepository
  {
      IEnumerable&lt;City&gt; Cities { get; }
      void AddCity(City newCity);
  }
  
  public class MemoryRepository : IRepository
  {
      private readonly List&lt;City&gt; cities = new List&lt;City&gt;();
  
      public IEnumerable&lt;City&gt; Cities =&gt; cities;
  
      public void AddCity(City newCity) =&gt; cities.Add(newCity);
  }
  </code></pre>
  <p>My <code>Startup</code> class contains the default-generated code from the template. I have made any changes:</p>
  <pre class="lang-cs prettyprint-override"><code>public class Startup
  {
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddControllersWithViews();
      }
  
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          ...
      }
  }
  </code></pre>