What I know understand is that it can be done, but that you need to be precise on the lifetime and scope of a grain and the db context.

The db context is meant to be living for one single unit of work whereas a grain is long lived.

That means, you’re responsible for managing the scope yourself.

  1. Use a DbContextFactory.
  2. With a correct using- statement in code scope the use of the db context

Investigation on Discord, multiple mentions of the pattern described above: