简体   繁体   中英

Injecting dependency into base class

I have the following BaseClass:

public class BaseRepositorio : IDisposable
{
    protected IDbConnection postgresql;

    public BaseRepositorio(IDbConnection postgresql)
    {
        this.postgresql = postgresql;
    }

    public void Dispose()
    {
    }
}

What is the proper way to inject the dependency into the BaseClass?

public class RepositorioEmpresa : BaseRepositorio?!?!, IRepositorio<Empresa>
{
}

Inject it in the derived and use base constructor

public class RepositorioEmpresa : BaseRepositorio, IRepositorio<Empresa>
{
    public RepositorioEmpresa(IDbConnection connection): base(connection)
    {
    }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM