O que é?
Uma técnica que permite a inserção de um objeto em outro, geralmente através do construtor, criando a relação de dependência.
O método que utilizamos para adicionar configurações para o Controller é um exemplo de injeção de Dependência.
Técnica muito utilizada para melhorar a qualidade de código em refatorações, e torná-lo mais testável.
ASP.Net Core
Windows
- Baixar a versão estável mais atualizada do Visual Studio 2019.
- Usar o instalador para obter as ferramentas para desenvolvimento de ASP.NET Core
Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
// This method gets called by the runtime. Use this method to add services to the container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Soma de vários inteiros | |
/// </summary> | |
/// <param name="numeros">Números que deseja somar</param> | |
/// <example>SomarVarios(1, 2, 4, 5, 6)</example> | |
/// <returns>Soma</returns> | |
public static int SomarVarios(params int[] numeros) | |
{ | |
int soma = 0; | |
foreach (int numero in numeros) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Construtor | |
/// <![CDATA[ctor]]> | |
/// </summary> | |
public ClassNamePlaceholder() | |
{ | |
} | |
/// <summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Ignore Visual Studio temporary files, build results, and | |
## files generated by popular Visual Studio add-ons. | |
## | |
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore | |
# User-specific files | |
*.suo | |
*.user | |
*.userosscache | |
*.sln.docstates |