Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

cannot resolve scoped service from root provider.

$
0
0

I am using aspnet core 3.0  and getting the following error in the package manager   **Cannot resolve scoped service 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Bumples.Models.ApplicationDBContext]' from root provider.**

Below is the startup

using Bumples.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;

namespace Bumples
{
public class Startup
{
private readonly IConfiguration _config;

public Startup(IConfiguration config)
{
_config = config;

}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDBContext>();
services.AddDbContextPool<Models.ApplicationDBContext>(options => options.UseSqlServer(_config.GetConnectionString("CustomersDBConnection")));
services.AddScoped<ICustomersRepository, SQLCustomersRepository>();   Here is where the problem is

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// 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.UseStaticFiles();

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}

Here is the Application DBContext

using Microsoft.EntityFrameworkCore;

namespace Bumples.Models
{
public class ApplicationDBContext : DbContext
{
public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)
{ }
public DbSet<Customers> Customers { get; set; }


}
}

Hope someone can help.  I am just starting core 3.0

Thanks

Jen


Viewing all articles
Browse latest Browse all 9386

Trending Articles