Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to expose _sharedConnectionDepth as a read-only public property #633

Open
BobT2022 opened this issue Jan 13, 2022 · 2 comments

Comments

@BobT2022
Copy link

Hi all,

It would be very beneficial for diagnostic tracing purposes throughout my application code if I could report on the _sharedConnectionDepth count either as a public read-only property of the PetaPoco IDatabase instance, and/or within the DbConnectionEventArgs arguments of the ConnectionOpened and OnConnectionClosing events. That way I can keep track of any issues arising from explicit shared connections being opened but not subsequently being closed (thus creating an imbalance that may result in the final IDatabase dispose not closing the connection when ordinarily it should).

Thanks, and great job everyone!

@asherber
Copy link
Collaborator

My concern with exposing this implementation detail would be that it doesn't always mean what the user might think it does. For example, if you do var db = new Database(myConnection), then _sharedConnectionDepth is automatically set to 2, regardless of the actual connection state. This is because when a connection is passed in, the caller is responsible for opening it and closing it; setting it to 2 prevents PetaPoco from closing it when the Database is disposed. (Yes, there are other ways the library might have implemented this.)

If this is something you need for tracing purposes, then my suggestion would be to access it yourself with reflection.

@BobT2022
Copy link
Author

Ok, however in my case I'm wrapping Database in a UnitOfWork such that it makes passing around the DB instance more abstract to the developer (along with other reasons) - to which the caller only ever supplies a connection string not a connection instance for the very reason that I don't want orphaned connections left in error if a dev doesn't remember to close a connection they explicitly opened. Not ideal using reflection either as that'll be a massive assumption that the internals of PetaPoco never change.

I'll close off this request now as it's not massively important at the moment, plus I can always hook into the ConnectionOpened and OnConnectionClosing events in my UnitOfWork and report that way.

Thanks anyway :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants