injectable
injectable copied to clipboard
How pass parameter to @singleton/lazysingleton?
Need to create localdatasource with moor, but before get async queryExecutor.
Future<QueryExecutor> constructQueryExecutor() async {
if (kIsWeb) {
final storage = await web.MoorWebStorage.indexedDbIfSupported('db');
return web.WebDatabase.withStorage(storage);
} else
return flutter.FlutterQueryExecutor.inDatabaseFolder(path: 'db.sqlite');
}
@injectable
@UseMoor(
tables: [Users],
)
class LocalDatasource extends _$LocalDatasource {
LocalDatasource(QueryExecutor e) : super(e);
How make injectable localdatasource with passing parameter? Without injectable i easy pass argument to getIt and all works fine...
Use @factoryParam
annotaion. See here
Use
@factoryParam
annotaion. See here
But isnt it for factory? I need it for singleton, for same instance over app. Would it work ?
No @Elendiar, it will not work, as you probably already noticed. Did you manage to solve the problem? I'm facing same problem as I would like to share some singletons using a library, but they need some parameters to be adapted to each use case.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions