Please can you make Dispose in TestContextBase virtual #338
-
I need to dispose of a sql lite connection as recommended here: https://docs.microsoft.com/en-us/ef/core/testing/sqlite I'm inheriting from TestContext but cant override Dispose to add my connection.Dispose() line. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is virtual, or rather, the Please make sure you call An alternative you can consider is to simply add the SQLite connection to the Hope this helps. ps. will convert this to a QA discussion. |
Beta Was this translation helpful? Give feedback.
Hi @robalexclark
It is virtual, or rather, the
Dispose(bool disposing)
method is. This follows the recommended disposing pattern described here: https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose#implement-the-dispose-pattern-for-a-derived-class.Please make sure you call
base.Dispose(disposing)
from your overwrite of this method when you are done with the disposing steps you need.An alternative you can consider is to simply add the SQLite connection to the
Services
collection/provider. This will take care of disposing it for you, if you allow the service provider to create the SQLite instance.Hope this helps.
ps. will convert this to a QA discussion.