Problem uploading Api web in Asp.net core using entity framework with postgresql

1

Hello! So I've mapped my classes to the bank, mirrored successfully, and started to build the features of my webservice. With this, I came across the following error:   InvalidOperationException: Unable to resolve service for type 'CadFuncionario.Interface.IFuncionario Repository' while attempting to activate 'CadFuncionario.Controllers.FuncionarioController

Follow my driver:

[Produces("application/json")]
[Route("api/Home")]
public class FuncionarioController : Controller
{
    private readonly IFuncionarioRepositorio _context;

    public FuncionarioController(IFuncionarioRepositorio context)
    {
        _context = context;
    }

    [HttpGet]
    public IEnumerable<Funcionario> GetAll()
    {
        return _context.ListarTodos();
    }

}

My repository:

public interface IFuncionarioRepositorio
{
    //CRUDs Funcionario
    void Adicionar(Funcionario Func);
    void AttFuncionario(Funcionario Func);
    void DelFuncionario(int IdFunc);
    IEnumerable<Funcionario> ListarTodos();
}

The implementation of my interface:

public class FuncionarioRepositorio : IFuncionarioRepositorio
{
    private CadFuncContext _context;

    public FuncionarioRepositorio(CadFuncContext context)
    {
        _context = context;
    }

    public void Adicionar(Funcionario Func)
    {
        _context.Add(Func);
        _context.SaveChanges();
    }

    public void AttFuncionario(Funcionario Func)
    {
        _context.Update(Func);
        _context.SaveChanges();
    }

    public void DelFuncionario(int IdFunc)
    {
        throw new NotImplementedException();
    }

    public IEnumerable<Funcionario> ListarTodos()
    {
        return _context.funcionario;
    }
}

And the service, I'm adding it like this:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddEntityFrameworkNpgsql().AddDbContext<CadFuncContext>(opt =>
        opt.UseNpgsql(Configuration.GetConnectionString("Conn")));
        services.AddMvc();
    }

I'll be waiting anxiously for a little help rs

    
asked by anonymous 13.11.2017 / 01:35

0 answers