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..

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.