I'm building a Worker Service who is a separated project from my main Web project. This Worker Service is responsible for consume RabbitMQ messages and send this message to MailSender. But, I'm not realizing how to register what I need as Dependency Injection. I figure out how to include these services in IoC, doing this:
// Create RabbitMQ connection to send as DI
container.Register<IModel>(() => CreateChannel(container), Lifestyle.Singleton);
container.Register<EmailConfig>(() => ConfigureMail(container), Lifestyle.Singleton);
container.Register<IEmailSender, EmailSender>(Lifestyle.Singleton);
The problem is that my Worker.cs have to receive ILogger<Worker>, EmailSender emailSender, IModel channel as DI and I figure out how to register my Email configurations, but I can't reach how to register these ILogger and IModel. So, my ConfigureServices from Startup.cs is like that:
var mailConfig = Configuration.GetSection("SMTP").Get<EmailConfig>();
services.AddSingleton(mailConfig );
var rabbitConfig = Configuration.GetSection("RabbitMQ").Get<RabbitMQConfig>();
services.AddSingleton(rabbitConfig);
services.AddSingleton<IEmailSender, EmailSender>();
IModel is from RabbitMQ (AMQP Model)