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 IActionResult EnviarMensagem(IServiceProvider serviceProvider, int clienteId) | |
{ | |
//busca o cliente pelo clienteId informado | |
var cliente = new Cliente | |
{ | |
Nome = "Vinicius Mussak", | |
TipoCliente = "Premium", | |
Id = clienteId | |
}; |
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 ClienteController : ControllerBase | |
{ | |
private readonly IMensagemBoasVindas _mensagemBoasVindas; | |
public ClienteController([FromKeyedServices("Padrao")] IMensagemBoasVindas mensagemBoasVindas) | |
{ | |
_mensagemBoasVindas = mensagemBoasVindas; | |
} | |
//demais métodos... | |
} |
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
builder.Services.AddKeyedScoped<IMensagemBoasVindas, MensagemBoasVindasPadrao>("Padrao"); | |
builder.Services.AddKeyedScoped<IMensagemBoasVindas, MensagemBoasVindasPremium>("Premium"); |
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 ClienteController : ControllerBase | |
{ | |
private readonly IEnumerable<IMensagemBoasVindas> _mensagensBoasVindas; | |
public ClienteController(IEnumerable<IMensagemBoasVindas> mensagensBoasVindas) | |
{ | |
_mensagensBoasVindas = mensagensBoasVindas; | |
} | |
//demais métodos... | |
} |
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 ClienteController : ControllerBase | |
{ | |
private readonly IMensagemBoasVindas _mensagemBoasVindas; | |
public ClienteController(IMensagemBoasVindas mensagemBoasVindas) | |
{ | |
_mensagemBoasVindas = mensagemBoasVindas; | |
} | |
//demais métodos... | |
} |
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
builder.Services.AddScoped<IMensagemBoasVindas, MensagemBoasVindasPadrao>(); | |
builder.Services.AddScoped<IMensagemBoasVindas, MensagemBoasVindasPremium>(); |
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 interface IMensagemBoasVindas | |
{ | |
string CriarMensagem(Cliente cliente); | |
} | |
public class MensagemBoasVindasPadrao : IMensagemBoasVindas | |
{ | |
public string CriarMensagem(Cliente cliente) | |
{ | |
return $"Olá, {cliente.Nome}, estamos felizes que esteja conosco!"; |
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 MensagemBoasVindas | |
{ | |
public string CriarMensagem(Cliente cliente) | |
{ | |
if (cliente.Tipo == "Padrão") | |
{ | |
return $"Olá, {cliente.Nome}, estamos felizes que esteja conosco!"; | |
} | |
else if (cliente.Tipo == "Premium") | |
{ |
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
var builder = WebApplication.CreateBuilder(args); | |
//...outras configurações | |
builder.Services.AddScoped<IMensagem, Mensagem>(); | |
//Outras configurações... |
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 interface IMensagem | |
{ | |
string RetornaMensagem(string nome); | |
} | |
public class MensagemBoasVindas : IMensagem | |
{ | |
public string RetornaMensagem(string nome) | |
{ | |
return $"Olá {nome}, estamos felizes em lhe receber!"; |
NewerOlder