How do I instantiate the ApplicationdbContext class in a data access repository. Because my project is using ASP Identity, and in the ApplicationDbContext class the compiler asks for an argument of type DbContextOptions <ApplicationDbContext> but I can not instantiate this class of mode that works and thus perform the operations of access to the bank with entity framework.
Statup
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
);
services.AddIdentity<ApplicationUser, IdentityRole>(config =>
{
config.Password.RequiredLength = 6;
config.Password.RequireDigit = true;
config.Password.RequireLowercase = false;
config.Password.RequireNonAlphanumeric = false;
config.Password.RequireUppercase = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Add application services.
services.AddTransient<IEmailSender, EmailSender>();
services.AddTransient<IFilesRepositorio, FilesRepositorio>();
services.AddTransient<INFeRepositorio , NFeRepositorio>();
services.AddMvc();
}
ApplicationDbContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{}
public DbSet<NotaFiscal> NFes { get; set; }
public DbSet<NFeDet> Produtos { get; set; }
}
Repository
public class NFeRepositorio : INFeRepositorio
{
//Need Instantiate ApplicationbContext here
}
seems to be simple, but I did not get the class instance, someone help me ?
Thank