Multiple hosted services of the same type with different configurations?

Viewed 111

I have a service I am trying to implement for an ASP.NET application, SomeService which is an implementation of BackgroundService responsible for consuming messages off of a message queue. There are several different queues that I would like to consume at the same time, but with different delays. For example:

[
    {
        "queueName": "queue1",
        "interval": 5
    },
    {
        "queueName": "queue2",
        "interval": 10
    }
]

I would like to be able to register two instances of someService, one for queue1 and one for queue2

Is it possible to do something like configurations.ForEach(x=> services.AddHostedService<SomeService>(x)); with each instance of the service running with its own configuration?

0 Answers
Related