title: Unable to resolve service for type when using my repository
body: <p>When I try and access my repository, I receive an error:</p>
  <blockquote>
  <p>InvalidOperationException: Unable to resolve service for type 'software.Notes.Repositories.NoteRepository' while attempting to activate 'software.Notes.Http.Handlers.ShowNote'.</p>
  </blockquote>
  <p>So, I have a simple SoftwareContext:</p>
  <pre><code>public class SoftwareContext : DbContext
  {
      public SoftwareContext(DbContextOptions options)
              : base(options)
          { }
          
          public DbSet&lt;Contact&gt; Contact { get; set; }
  
          public DbSet&lt;Note&gt; Note { get; set; }
      }
  }
  </code></pre>
  <p>which is instantiated in my startup.cs file:</p>
  <pre><code>services.AddDbContext&lt;SoftwareContext&gt;(options =&gt;
      options.UseMySql(
          Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));
  </code></pre>
  <p>Now, I have a simple request handler to show a note:</p>
  <pre><code>[ApiController]
  public class ShowNote : Controller
  {
      private readonly NoteRepository _note;
  
      public ShowNote(NoteRepository note)
      {
          _note = note;
      }
  
      [HttpGet]
      [Route(&quot;note/show/{id}&quot;)]
      public IActionResult init(int id)
      {
          Note note = _note.Find(id);
  
          if (note != null) {
              return Ok(note);
          }
  
          return NotFound();
      }
  }
  </code></pre>
  <p>And inside my repository I have the following:</p>
  <pre><code>public abstract class NoteRepository : INoteRepository
  {
      private readonly SoftwareContext _context;
  
      protected NoteRepository(SoftwareContext context)
      {
          _context = context;
      }
      
      public Note Create(Note note)
      {
          var add = _context.Note.Add(note);
  
          return note;
      }
  
      public Note Find(int id)
      {
          return _context.Note.FirstOrDefault(x =&gt; x.Id.Equals(id));
      }
  }
  </code></pre>
  <p>Shouldn't the Context be injected via the constructor of my repository like I am currently doing? Can someone explain why this isn't working, and what the correct way to do it for it to work would be?</p>
  <p>Full exception log:</p>
  <blockquote>
  <p>System.InvalidOperationException: Unable to resolve service for type 'software.Notes.Repositories.NoteRepository' while attempting to activate 'software.Notes.Http.Handlers.ShowNote'.
  at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
  at lambda_method(Closure , IServiceProvider , Object[] )
  at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.&lt;&gt;c__DisplayClass4_0.b__0(ControllerContext controllerContext)
  at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.&lt;&gt;c__DisplayClass5_0.g__CreateController|0(ControllerContext controllerContext)
  at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
  at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
  at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
  at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
  at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
  at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
  at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
  at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
  at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
  at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)</p>
  </blockquote>