0

I'm trying to create a solution with separated classes, so I have:

public class RepositorioPadrao<TEntidade> : IRepositorioPadrao<TEntidade>
    where TEntidade : class
{

    public readonly ISQLiteConnection _connection;

    public RepositorioPadrao(ISQLiteConnectionFactory factory)
    {
        _connection = factory.Create("easybudget.sql");
        _connection.CreateTable<TEntidade>();
    }

    public virtual void Inserir(TEntidade objeto)
    {
        _connection.Insert(objeto);
    }

Then to use this I have:

public class RepositorioDeCategoria : RepositorioPadrao<Categoria>, IRepositorioDeCategoria
{
    public List<Categoria> ObterTudo()
    {
        return _connection
                .Table<Categoria>()
                .OrderByDescending(x => x.Descricao)
                .ToList();
    }
}

The problem is, that EasyBudget.Core.Repositorio.RepositorioPadrao<EasyBudget.Core.Dominio.Categoria> does not contain a constructor that takes 0 arguments.

Chorel
  • 362
  • 1
  • 13
Wilton
  • 218
  • 2
  • 11

1 Answers1

0

To solve your current problem, you could add a constructor to RepositorioDeCategoria that calls the base class:

 public RepositorioDeCategoria(ISQLiteConnectionFactory factory)
       : base(factory)
 {
 }

Alternatively, if you were going to have several Categoria and you wanted them to share the same _connection, then you might want to reorganise your classes so that they use some form of aggregration instead of inheritance.

Stuart
  • 66,722
  • 7
  • 114
  • 165