Skip to content

Instantly share code, notes, and snippets.

@vmussak
Created January 3, 2024 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmussak/7ce1a64065f081f25565b84e2a4e05c8 to your computer and use it in GitHub Desktop.
Save vmussak/7ce1a64065f081f25565b84e2a4e05c8 to your computer and use it in GitHub Desktop.
public IActionResult EnviarMensagem(IServiceProvider serviceProvider, int clienteId)
{
//busca o cliente pelo clienteId informado
var cliente = new Cliente
{
Nome = "Vinicius Mussak",
TipoCliente = "Premium",
Id = clienteId
};
//Recupera a instância pelo tipo do cliente
var service = serviceProvider.GetRequiredKeyedService<IMensagemBoasVindas>(cliente.TipoCliente);
var mensagem = service.CriarMensagem(cliente);
return Ok(mensagem);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment