I have a singleton, RabbitMQ Singleton, which works fine, but has a service dependency with scope every time a message arrives:
consumer.Received += _resourcesHandler.ProcessResourceObject;
My services are registered as follows:
services.AddScoped<IHandler, Handler>();
services.AddSingleton<RabbitMqListener>();
Limited service constructors use DI for the Db context:
private readonly ApplicationDbContext _appDbContext;
public ResourcesHandler(ApplicationDbContext appDbContext)
{
_appDbContext = appDbContext;
}
This namespace service calls a Db context to insert properties into the database when a message is received.
However, since the service with the scope has a different lifespan, the launch is not performed.
Is there a better way to do this? I could make the cloud service single, but then I would have a problem using DbContext as a dependency.
What is the “protocol” in DI for calling dbContext in single-user services?
using, , , DbContextOptions, DI. ?