0

Is it the best way to pass context object as parameter to another C# method?

Can somebody advise, passing it this way will lead to any issues ??

Thanks in advance..

mmssaann
  • 1,507
  • 6
  • 27
  • 55

1 Answers1

1

Passing a DbContext as a parameter isn't a problem at all -- there's nothing particularly special about it. It's just another class.

The only issue that jumps to mind is one that would be the same for any IDisposable -- the .NET developer guidelines recommend that only the class responsible for creating the IDisposable should dispose of it.

...that can be tricky to determine if you are using a dependency injection framework (eg Ninject) as it is sort of a mystery to any of the code written by the application where the objects are created.

To that end, you should never bind an IDisposable object in TransientScope:

Guidelines For Dispose() and Ninject

Community
  • 1
  • 1
fordareh
  • 2,923
  • 2
  • 26
  • 39