I have a service-class that looks like:
class BillingService
{
public void CheckBillingStatus(BillingOperationRequestDto dto)
{
}
public void AnotherOperationOnBillings(BillingOperationRequestDto dto)
{
}
}
Also I have another class that listen to some queue from RabbitMq. I want to write something like:
class MessageListener<T> where T : BaseDto {
public void GetMessage<T>(Func ... )
MessageListener<T>(string queueToListen)
{
}
}
The idea behind this code is that I want to use it as:
BillingService bs = new BillingService();
var listener = new MessageListener<BillingOperationRequestDto>();
listener.GetMessage<BillingOperationRequestDto>(bs.CheckBillingStatus);
I want to specifiy not only the data expected from queue, but also which method to invoke on this data. Is it correct approach? I thought about getting only one message from queue and than send data to another class, but didn't find an apporach to do it, so decided to run GetMessage in loop and specify what action should be performed when message appears.
Update #1.1: Is there a way to send a delegate to
listener.GetMessage<BillingOperationRequestDto>(bs.CheckBillingStatus);
if my methods in BillingService class will have different method signatures? For example,
public BillingStatusResult CheckBillingStatus(BillingOperationRequestDto dto)
{
}
public AnotherReturnValue AnotherOperationOnBilling(BillingOperationRequestDto dto, string requestedIp, TimeSpan period)
{
}