title: Unable to create an object of type 'ApplicationDbContex' Blazor ASP.NET Core 6.0
body: <p>I'm creating a web application in Blazor ASP.NET Core web hosted with ASP.NET Core 6 and when I'm migrating the database I'm getting this error:</p>
  <blockquote>
  <p>Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see <a href="https://go.microsoft.com/fwlink/?linkid=851728" rel="nofollow noreferrer">https://go.microsoft.com/fwlink/?linkid=851728</a></p>
  </blockquote>
  <p>I need to get a solution - this is my code:</p>
  <p>Program.cs</p>
  <pre><code>var builder = WebApplication.CreateBuilder(args);
  
  builder.Services.AddRazorPages();
  
  builder.Services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
              options.UseSqlServer(builder.Configuration.GetConnectionString(&quot;Prueba&quot;)));
  
  builder.Services.AddDefaultIdentity&lt;ApplicationUser&gt;()
                     .AddRoles&lt;IdentityRole&gt;()
                     .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;();
  
  builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                     .AddJwtBearer(options =&gt;
                     {
                         options.TokenValidationParameters = new TokenValidationParameters
                         {
                             ValidateIssuer = true,
                             ValidateAudience = true,
                             ValidateLifetime = true,
                             ValidateIssuerSigningKey = true,
                             ValidIssuer = builder.Configuration[&quot;JwtIssuer&quot;],
                             ValidAudience = builder.Configuration[&quot;JwtAudience&quot;],
                             IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration[&quot;JwtSecurityKey&quot;]))
                         };
                     });
  
  builder.Services.AddAuthorization(config =&gt;
   {
      config.AddPolicy(Policies.IsAdmin, Policies.IsAdminPolicy());
      config.AddPolicy(Policies.IsUser, Policies.IsUserPolicy());
   });
  builder.Services.AddSignalR();
  
  builder.Services.AddMvc().AddNewtonsoftJson(options =&gt;
             options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
  builder.Services.AddControllersWithViews();
  //builder.Services.AddRazorPages();
  builder.Services.AddResponseCompression(option =&gt;
  {
      option.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat
  
      (new[] { &quot;application/octet-stream&quot;
      });
  });
  
  var app = builder.Build();
  
  using (var scope = app.Services.CreateScope())
  {
      var services = scope.ServiceProvider;
  
      SeedData.Initialize(services);
  }
  
  // Configure the HTTP request pipeline.
  if (app.Environment.IsDevelopment())
  {
      app.UseDeveloperExceptionPage();
      app.UseWebAssemblyDebugging();
  }
  else
  {
      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.UseBlazorFrameworkFiles();
  app.UseStaticFiles();
  
  app.UseRouting();
  
  app.UseAuthentication();
  app.UseAuthorization();
  
  
  app.MapRazorPages();
  app.MapControllers();
  app.MapFallbackToFile(&quot;index.html&quot;);
  app.UseEndpoints(endpoints =&gt;
  {
      endpoints.MapHub&lt;UsuariosHub&gt;(&quot;/UsuariosHub&quot;);
  });
  app.Run();
  </code></pre>
  <p>ApplicationDbContext.cs</p>
  <pre><code>using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore;
  using ProyectoBP.Shared.Models;
  
  namespace ProyectoBP.Server.Data;
  
  public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options)
        : base(options)
      {
      }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
      }
  
      public DbSet&lt;Movie&gt; Movies { get; set; }
  }
  </code></pre>
  <p>SeedData.cs</p>
  <pre><code>using Microsoft.EntityFrameworkCore;
  using ProyectoBP.Server.Data;
  
  namespace ProyectoBP.Shared.Models
  {
      public static class SeedData
      {
          public static void Initialize(IServiceProvider serviceProvider)
          {
              using (var context = new ApplicationDbContext(
                  serviceProvider.GetRequiredService&lt;
                      DbContextOptions&lt;ApplicationDbContext&gt;&gt;()))
              {
                  context.SaveChanges();
  
                  if (context == null || context.Movies == null)
                  {
                      throw new ArgumentNullException(&quot;Null ApplicationDbContext&quot;);
                  }
  
                  // Look for any movies.
                  if (context.Movies.Any())
                  {
                      return;   // DB has been seeded
                  }
                    
                  context.SaveChanges();
              }
          }
      }
  }
  </code></pre>
  <p>appsettings.json</p>
  <pre><code>{
    &quot;AllowedHosts&quot;: &quot;*&quot;,
    &quot;ConnectionStrings&quot;: {
      &quot;DefaultConnection&quot;: &quot;Data Source=ISMAEL-PC;Initial Catalog=BP;Integrated Security=False;uid=JoseD;password=Laugama2021.&quot;,
      &quot;Prueba&quot;: &quot;Data Source=ISMAEL-PC;Initial Catalog=BP;Integrated Security=true&quot;
    },
    &quot;Logging&quot;: {
      &quot;LogLevel&quot;: {
        &quot;Default&quot;: &quot;Information&quot;,
        &quot;Microsoft&quot;: &quot;Warning&quot;,
        &quot;Microsoft.Hosting.Lifetime&quot;: &quot;Information&quot;
      }
    }
  }
  </code></pre>
  <p>I don't have a <code>StartUp</code> Class because apparently in ASP.NET Core 6 it's not needed</p>