I'm working with ASP.NET CORE 2
and it's a Layer application.
This is my ConfigureServices
no 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 appearing when starting the (Updated) Stack:
InvalidOperationException: Unable to resolve service for type 'ddd.Infrastructure.Data.ApplicationContext' while attempting to activate 'ddd.Infrastructure.Repositories.UsuarioRepository'.
Follow 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;
}
}
Follow 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.