# BsqliteDatabase (Class) `Bit.Bsqlite.Interop.BsqliteDatabase` - package `Bit.Bsqlite` - `using Bit.Bsqlite.Interop;` - implements `IAsyncDisposable`, `IDisposable` One named database for the lifetime of the application: opened on first use, shared by every caller, and closable so that admin operations can replace the file underneath. A Blazor WebAssembly application is one process with one user, so the natural shape is a singleton session per database rather than a pool. This type is that singleton. It is what the EF Core integration's context factory opens through, and what an application should inject when it wants the connection directly. BsqliteDatabase.CloseAsync tears the worker down. Subscribers to BsqliteDatabase.Closing drop the connections and live queries they hold; subscribers to BsqliteDatabase.Opened reopen. That is the protocol for moving a database between backends or importing a file over it. ## Constructor - **BsqliteDatabase**(IBsqliteSessionFactory sessions, string databaseName) ## Property - **Connection** : `BsqliteConnection` - The open connection, or null when the database is not open. - **IsOpen** : `bool` - Whether a session is currently open. - **Name** : `string` - The database this instance opens. - **Provider** : `IBsqliteStorageProvider` - The provider holding the data, when the database is open. - **Resolution** : `BsqliteStorageResolution` - Why the current backend was chosen, when the database is open. - **Session** : `BsqliteSession` - The open session, or null before the first open or after a close. ## Method - **CloseAsync**(CancellationToken cancellationToken = default) : `Task` - Closes the session and terminates its worker, after giving BsqliteDatabase.Closing subscribers the chance to let go. A no-op when the database is not open. - **Dispose**() : `void` - Synchronous disposal, for containers that dispose synchronously. The worker is torn down asynchronously in the background; prefer BsqliteDatabase.DisposeAsync where possible. - **DisposeAsync**() : `ValueTask` - **ExportAsync**(CancellationToken cancellationToken = default) : `Task` - Reads the open database out as a SQLite file image, consistent as of the last committed write, without closing it. - **OpenAsync**(CancellationToken cancellationToken = default) : `ValueTask` - Opens the database if it is not open and returns the session. - **ReopenAsync**(CancellationToken cancellationToken = default) : `Task` - Closes and reopens, which is how a changed binding or an imported file takes effect. - **WhileClosedAsync**(Func work, CancellationToken cancellationToken = default) : `Task` - Runs work with the database closed and reopens afterwards, so an admin operation never races the worker that holds the file open. ## Event - **Closing** : `Func` - Raised before the session is closed. Handlers must release every connection, context, and live query bound to it; the worker is terminated once they return. - **Opened** : `Func` - Raised after a session opens, including the first time.