Closed MaslovD closed 3 years ago
There is a directory with examples.
You can inject IProducingService
inside your service or controller simply doing this
namespace Examples.AdvancedConfiguration.Controllers
{
[ApiController]
[Route("api/example")]
public class ExampleController : ControllerBase
{
private readonly ILogger<ExampleController> _logger;
private readonly IProducingService _producingService;
public ExampleController(
IProducingService producingService,
ILogger<ExampleController> logger)
{
_producingService = producingService;
_logger = logger;
}
[HttpGet]
public async Task<IActionResult> Get()
{
_logger.LogInformation($"Sending messages with {typeof(IProducingService)}.");
var message = new { message = "text" };
await _producingService.SendAsync(message, "consumption.exchange", "routing.key");
return Ok(message);
}
}
}
But if for some reason you want to use IConsumingService
you can inject it the same way as a IProducingService
.
I actually wanna add few more examples both for the documentation section and for examples directory.
where to find simple demonstration of how to inject RabbitMQ client into service?