Answer the question
In order to leave comments, you need to log in
How to instantiate IOptions?
Quite a simple problem) There is a service that works with RabbitMQ.
public class MessageService : IMessageService
{
private readonly ConnectionFactory _factory;
private readonly IConnection _connection;
private readonly IModel _channel;
private readonly IOptions<RabbitMQSettings> _rabbitSettings;
public MessageService(IOptions<RabbitMQSettings> rabbitSettings)
{
_rabbitSettings = rabbitSettings;
_factory = new ConnectionFactory()
{
HostName = rabbitSettings.Value.HostName,
Port = rabbitSettings.Value.Port,
UserName = rabbitSettings.Value.UserName,
Password = rabbitSettings.Value.Password
};
_connection = _factory.CreateConnection();
_channel = _connection.CreateModel();
}
class Client
{
static void Main(string[] args)
{
IOptions<RabbitMQSettings> _rabbitSettings;
var client = new MessageService(IOptions<RabbitMQSettings> rabbitSettings)
{
};
}
}
Answer the question
In order to leave comments, you need to log in
IOptions can be created with Options.Create
IOptions<A> options = Options.Create(new A());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question