Note that this similar sounding question does not in fact answer my question.
I have a class which involves reading a message from a queue and processing it. I was trying to use a method in another class to handle it, and couldn't manage it without making it static, and wondered what the best way to do this would be.
So this is the code with the HandleMessage in the same class:
myconfigclass {
protected override void DoConfigure(IDependancyInjectionContainer container)
{
IServiceInformation serviceDetail = m_ServiceDiscovery.GetServiceEndpoint("rabbitmq").Result;
string rabbitMqAddress = $"{serviceDetail.IpAddress}:{serviceDetail.Port}";
RabbitMqServer mqServer = new RabbitMqServer(rabbitMqAddress);
mqServer.RegisterHandler<CdsGatewayMessage>(HandleMessage); //want HandleMessage to be in another class
mqServer.Start();
}
public object HandleMessage(IMessage<CdsGatewayMessage> message)
{//does stuff with the message
}
What I want to do is to move HandleMessage into another class MessageProcessor, but I can only get this to work by making MessageProcessor.HandleMessage() static.
Is there a simple way to get this to work in an external class as an instance?