title: EF Core - Unable to resolve service for type DbContext while attempting to activate ApplicationContext
body: <p>I am attempting to scaffold CRUD razor pages using entity framework but the code generator throws the following error:</p>
  <blockquote>
  <p>There was an error running the selected code generator: ‘Unable to resolve service for type ‘Microsoft.EntityFrameworkCore.DbContextOptions`1[TenthBatchTracker.Data.TenthContext’] while attempting to activate ‘TenthBatchTracker.Data.TenthContext’.’</p>
  </blockquote>
  <p>Program.cs</p>
  <pre><code>using Microsoft.EntityFrameworkCore;
  using TenthBatchTracker;
  using TenthBatchTracker.Data;
  using Microsoft.Extensions.DependencyInjection;
  
  var builder = WebApplication.CreateBuilder(args);
  
  // Add services to the container.
  builder.Services.AddRazorPages();
  
  // DI for Automapper
  builder.Services.AddAutoMapper(typeof(AutomapperProfile));
  
  //Scaffolded Code to compare to mine
  builder.Services.AddDbContext&lt;TenthBatchTrackerContext1&gt;(options =&gt;
  
      options.UseSqlServer(builder.Configuration.GetConnectionString(&quot;TenthBatchTrackerContext1&quot;)));
  
  // My DI for EF
  builder.Services.AddDbContext&lt;TenthContext&gt;(options =&gt;
      options.UseSqlServer(builder.Configuration.GetConnectionString(&quot;TenthContext&quot;)));
  
  
  
  
  var app = builder.Build();
  
  
  // Configure the HTTP request pipeline.
  if (!app.Environment.IsDevelopment())
  {
      app.UseExceptionHandler(&quot;/Error&quot;);
      // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
      app.UseHsts();
  }
  
  app.UseHttpsRedirection();
  app.UseStaticFiles();
  
  app.UseRouting();
  
  app.UseAuthorization();
  
  app.MapRazorPages();
  
  app.Run();
  </code></pre>
  <p>DbContext (DbSets Omitted)</p>
  <pre><code>using Microsoft.EntityFrameworkCore;
  using TenthBatchTracker.Domain.Models;
  
  namespace TenthBatchTracker.Data
  {
      public class TenthContext : DbContext
      {
  
          public TenthContext (DbContextOptions&lt;TenthContext&gt; options) 
              : base(options)
          {
  
          }
  
       
      }
  }
  </code></pre>
  <p>In my program.cs I am using builder.Services.AddDbContext for dependency injection of my DbContext class and the DbContext options.
  My class for my application DbContext is passing those options to the base constructor.
  I have also generated a new DBConext using the scaffolding tool and compared my code for my Db Context and DI injection with that of the generated code, and I don’t see a difference. My app builds and runs, I just can't scaffold pages. What am I missing?</p>