Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
How do we know what are "Local Defaults" while using Property Injection?

I was reading the book Dependency Injection in .NET, by Mark Seemann, where I stumbled upon the topic of Property Injection.

As the book described for using the Property Injection the condition was:

1) When the use of Dependency Injection is optional
2) When we have a good Local Default

As I searched through the internet about "Local Default", I didn't get any significant definitions for this concept.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In both editions of the book, a definition and description of Local Default can be found in section 4.2.2. The second edition states:

DEFINITION: A Local Default is a default implementation of a Dependency that originates in the same module or layer.

Local Default

When you're developing a class that has a Dependency, you probably have a particular implementation of that Dependency in mind. If you're writing a domain service that accesses a Repository, you're most likely planning to develop an implementation of a Repository that uses a relational database.

It would be tempting to make that implementation the default used by the class under development. But when such a prospective default is implemented in a different assembly, using it as a default means creating a hard reference to that other assembly, effectively violating many of the benefits of loose coupling described in chapter 1. Such implementation is the opposite of a Local Default—it's a Foreign Default. A class that has a hard reference to a Foreign Default is applying the Control Freak anti-pattern. We'll discuss Control Freak in chapter 5.

Conversely, if the intended default implementation is defined in the same library as the consuming class, you won't have that problem. This is unlikely to be the case with Repositories, but such Local Defaults often arise as implementations of the Strategy pattern.

NOTE: The text for Local Default in the first edition is slightly different, but not that different. I used the text of the second edition, because I don't have the text of the first edition in an easily copy/pasteable form at my disposal.

TIP: Since you are at the beginning of the book, my advise would be to switch to the second edition, as it is the most recent version, and an overall improvement of the book. This blog post describes the improvements Mark and I made in that edition.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda