Constructor abstract class

2

I'm not able to develop the following environment:

public abstract class AplicacaoGenerica<TEntity> where TEntity : class
{
    private IRepositorio<TEntity> repositorio;
    public AplicacaoGenerica(IRepositorio<TEntity> repo)
    {
        repositorio = repo;
    }

      (...)
}

There is no error in this class.

public class BandeiraAplicacao : AplicacaoGenerica<Bandeira>
{

}

In this class the following error appears:

  

Does not contain a constructor that takes 0 arguments

public class BandeiraAplicacaoConstrutor
{
    public static BandeiraAplicacao BandeiraAplicacaoEF()
    {
        return new BandeiraAplicacao(new BandeiraRepositorioEF());
    }
}

Displays the following error:

  

Does not contain a constructor that takes 1 arguments

I have an abstract class, GeneralApplication, which has a constructor. Then I create a BandeiraApplication class that implements GeneralApplication. Then the Flag Class Application Builder tries to call the Flag builder Application.

    
asked by anonymous 09.09.2014 / 16:09

1 answer

2

You have to create a constructor with the same structure in sub class , something like this:

public class BandeiraAplicacao : AplicacaoGenerica<Bandeira>
{
     public BandeiraAplicacao(IRepositorio<TEntity> repo)
         // aqui estamos passando o argumento para a sub class 
         :base(repo)
     {
     }
}

The error you pointed out is saying that% base% has no empty constructor, for class class use in its construction.

So you have two options to solve this problem:

  • Pass the required parameter to% base_database in the child constructor (as in the example);
  • Create an empty constructor in BandeiraAplicacao base
  • 09.09.2014 / 16:16