3
Imagine the classic architecture:
Consoleapplication (Frontend) --> Business Layer (BLL) --> Data Access Layer (DAL)
That is, Frontend references BLL that references DAL. See that Frontend does not know the DAL, and nor should.
Since my container registration should be in the application’s Entry Point (Frontend) how I can register a dependency of a DAL layer repository if Frontend does not know DAL?
Imagine the following structure:
DAL
// Camada DAL
public class DAOPessoa : IDAOPessoa
{
public DAOPessoa()
{
}
public List<string> Obter()
{
return new List<string>() { "Pessoa 1", "Pessoa 2", "Pessoa 3" };
}
}
BLL
// CAMADA BLL
public class Processador
{
private readonly IDAOPessoa _daoPessoa;
public Processador(IDAOPessoa daoPessoa)
{
this._daoPessoa = daoPessoa;
}
public void Processar()
{
this._daoPessoa.Obter();
}
}
FRONTEND
//Um console application, por exemplo
public static class Program
{
static readonly Container container;
static Program()
{
// 1. Create a new Simple Injector container
container = new Container();
// 2. Configure the container (register)
container.Register<IDAOPessoa, DAOPessoa>(); // Aqui fica sublinhado em vermelhor pois este assembly (Frontend) não conheçe nada da DAL
// 3. Verify your configuration
container.Verify();
}
}
Is there any standard or recommendation to solve this problem?
A good approach too, so I understood then create a class library responsible for IOC referencing everyone that is necessary? and his "Frontend" calls this DLL and it does the job?
– Thiago Loureiro
That’s right. So you have a unique responsibility project.
– Thiago Lunardi
Very good, very good... From the beginning I imagined that this would be the ideal solution, I asked the question just to confirm and also because I saw several post arguing that the frontend itself could reference everything, in these posts people argued that reference the DAL DLL, For example, it does not necessarily create dependence between objects, this is true, but it is dangerous. The solution you suggest is much more elegant and safe.
– Ewerton