1

Our project is using multitenancy to resolve some Service, lets say MyService based on SaasKit.

We also have a background task, which shares some of it's dependencies with the asp.net core controllers.

In the background task, any object that depends on MyService will get a null reference.

I can implement workarounds to get instances of MyService, like using service locator pattern, but this approach fails to create classes that depend on MyService without breaking DI and IOC logic.

So the question is: How can I get the same services that I can get from HttpContext with multitenancy, but get them without an HttpCoontext?

Alireza
  • 5,421
  • 5
  • 34
  • 67
  • Can you show some code to better explain what it is you are asking in a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – Nkosi Oct 02 '19 at 11:15
  • What is `MyService` and how did you decide the tenancy in the background. When there is not request from client, the backgound will fail to access the HttpContext which is not exist while there is no request. For a workaround, you may try to create a task table which contains `TenantId`, and then run the task from background. – Edward Oct 08 '19 at 05:46
  • I actually need to give much more details and code. Will do that in a day or two – Alireza Oct 08 '19 at 11:33
  • 1
    @Alireza: Having the same issue. How did you resolve this issue ? – Himal Patel Aug 25 '20 at 04:37

0 Answers0