I have the following class:
public class SqlCeEventStore: EventStore { private EventStoreDB db; public SqlCeEventStore(EventStoreDB db) { this.db = db; } public void Dispose() { db.Dispose(); } }
My problem is this: am I disposing EventStoreDB in the Dispose method of my class, given that it was passed to it in the constructor (and therefore, maybe it can be reused after my class is deleted)?
That is, if I dispose of it, I affirm that the correct use of my class is:
using (var store = new SqlCeEventStore(new EventStoreDB)){ {
but I see that this alternative call is used:
using (var db = new EventStoreDB()) using (var store = new SqlCeEventStore(db)) {
in this case, I should not dispose of EventStoreDB from the SqlCeEventStore class.
Are there any arguments for one style or another? I want to choose one and stick to it, and I would not flip a coin :)
source share