RoomDatabaseConstructor



Defines a class that can instantiate the Room generated implementation of an 'abstract' Database annotated RoomDatabase definition.

This interface is to be used in conjunction with ConstructedBy to define an 'expect' declaration of an 'object' that implements this interface. The defined 'object' can then be optionally used in Room's databaseBuilder or inMemoryDatabaseBuilder as the factory.

For example, with the following object definition:

expect object MusicDatabaseConstructor : RoomDatabaseConstructor<MusicDatabase>

one can reference the object's initialize during database creation:

fun createDatabase(): MusicDatabase {
return Room.inMemoryDatabaseBuilder<MusicDatabase>(
factory = MusicDatabaseConstructor::initialize
).build()
}

For Room to correctly and automatically use 'actual' implementations of this interface, they must be linked to their respective Database definition via ConstructedBy.

Parameters
<T : RoomDatabase>

The Database and ConstructedBy annotated class linked to this constructor.

See also
ConstructedBy

Summary

Public functions

T

Instantiates an implementation of T.

Cmn

Public functions

initialize

fun initialize(): T

Instantiates an implementation of T.

Returns
T

T - A new instance of T.