[SUGGESTION] - Support a constructor that can receive an already instantiated LiteDatabase instance
Closed this issue · 2 comments
Hi,
First off, kudos for putting this lib together!
While going through the constructor options, I realized for example there is not overload for connection string + BSON mapper, which happens to be there in the LiteDatabase object. Your lib currently exposes either one or the other, but not both together.
So, instead of creating yet another overload, I was thinking maybe we could simplify this and give the consumer the ability to tweak a LiteDatabase
instance and feed your lib with it.
public LiteDatabaseAsync(LiteDatabase underlyingDatabase)
{
_liteDB = underlyingDatabase ?? throw new ArgumentNullException(nameof(underlyingDatabase));
_backgroundThread = new Thread(BackgroundLoop);
_backgroundThread.Start();
}
The good thing about it is: Things like Pragmas and indexes would be available to the caller (I know you got async overloads for the indexes, but it may not be the case for everybody)...and you wouldn't need to create a brand new overload every single time LiteDatabase
is changed.
The only con I can think of is the possibility of a external factor/leakage of the the reference in case the caller does not make a good use of it, but IMO this is all about good practices in the end.
I have written a fix for this
WIll merge in when I fix some other missing functionality this has revealed.
This fix is now in v0.0.5