2
I’m working with ASP.NET CORE 2
and is a layered application.
This is my ConfigureServices
in the Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<DbContext, ApplicationContext>();
services.AddTransient<IUsuarioRepository, UsuarioRepository>();
services.AddTransient<IUsuarioService, UsuarioService>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
Error that appears when starting apilication (Updated):
Invalidoperationexception: Unable to resolve service for type 'ddd.Infrastructure.Data.Applicationcontext' while attempting to Activate 'ddd.Infrastructure.Repositories.Usuariorepository'.
Follows my UsuarioRepository
public class UsuarioRepository : Repository<Usuario>, IUsuarioRepository
{
private readonly ApplicationContext _context;
public UsuarioRepository(ApplicationContext context) : base(context)
{
_context = context;
}
public bool ValidarUsuarioSenha(Usuario usuario)
{
return true;
}
}
Follows my ApplicationContext
public class ApplicationContext : DbContext
{
private string strConnection
="";
public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(options)
{
}
public DbSet<Usuario> Usuarios { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseNpgsql(strConnection);
}
}
}
*Updated Question.
didn’t work... that
DbContext
is EF core, correct? did not work– SM_S
Yes, what error message?
– Barbetta
InvalidOperationException: Unable to resolve service for type 'ddd.Infrastructure.Data.ApplicationContext' while attempting to activate 'ddd.Infrastructure.Repositories.UsuarioRepository'.
– SM_S
It would be possible to add in your question
contexto
and the classUsuarioRepository
and also theConfigureServices
up-to-date– Barbetta
OK I updated the question
– SM_S