0
I have a project that uses Unity Application Block dependency injection.
Has the repository class:
public class RepositorioDeLaudoMedico: RepositorioGenericoEntityFramework<LaudoMedico, int>,
IRepositorioDeLaudoMedico
{
public IDbConnection Conexao;
public RepositorioDeLaudoMedico(DbContext contexto) : base(contexto){} //construtor 1
public RepositorioDeLaudoMedico(IDbConnection conexao) //construtor 2
{
this.Conexao = conexao;
}
}
And in the dependency injection class it’s like this:
container.RegisterType<IRepositorioDeLaudoMedico, RepositorioDeLaudoMedico>(
new InjectionConstructor(
new ResolvedParameter(typeof(DbContext), "ContextoLocal")
)
);
How do I include the second constructor? I can’t touch the first because it comes from a dll...
Do you intend to remove this and insert the other one? What is the purpose of the exchange?
– novic
i know that in dependency injection the ideal is to use only 1 constructor...
– Rafaela Marraschi
because I need to create another access to the bank using Dapper
– Rafaela Marraschi
Okay, if you have that principle noted, imagine that two settings for the same record will not work, do you understand that? If you need to use
dapper
thecontexto
gives you also the class that is responsible to access the methods of Dapper, IE, does not need to be two settings, because it no longer works, only one and access the extension methods that Dapper provides in the namespace that has to be configured.– novic
EF Core: https://stackoverflow.com/questions/41935752/entity-framework-core-how-to-get-the-connection-from-the-dbcontext
– novic
Entity Frameword <=6: https://stackoverflow.com/questions/5286071/entity-framework-getting-an-sql-connection
– novic
These two ways propose to you and rescue
IDbConnection
! understands?– novic
@Rafaelamarraschi this was an old recommendation. nowadays the injection stack chooses the constructor with the largest number of injections it can solve.
– OnoSendai
Guys, thank you, I was able to solve, really with this variable I was able to catch the connection.
– Rafaela Marraschi