Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IdentityBuilder does not contain a definition for 'AddEntityFrameworkStores

I am using .netcore 3.1. While using the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;    
using Microsoft.Extensions.DependencyInjection;    
using Microsoft.Extensions.Hosting;    
using Microsoft.Extensions.Logging;    
///using AspNetCore3JWT.Data;    
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;        
using Microsoft.AspNetCore.Authentication.JwtBearer;    
using Microsoft.IdentityModel.Tokens;
using Jwt.Data;

namespace Jwt
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        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.AddControllers()
                   .AddNewtonsoftJson();

            services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                   .AddEntityFrameworkStores<ApplicationDbContext>()

                .AddDefaultTokenProviders();
        }

        // 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();
            }

            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

I got this error:

error-image-code

like image 771
Raju Gaddam Avatar asked Feb 04 '20 11:02

Raju Gaddam


People also ask

What does Addentityframeworkstores do?

Basically it adds default Stores: UserStore and RoleStore.

What is IdentityDbContext?

IdentityDbContext() Initializes a new instance of the IdentityDbContext class. IdentityDbContext(DbContextOptions) Initializes a new instance of IdentityDbContext.


1 Answers

I just upgraded a project to .net core 3.1, and had to change the following line from

services.AddDefaultIdentity<ApplicationUser>().AddEntityFrameworkStores<DBContext>();

To

services.AddDefaultIdentity<ApplicationUser>().AddUserStore<DBContext>();
like image 67
ShaunOReilly Avatar answered Sep 20 '22 20:09

ShaunOReilly