injectable icon indicating copy to clipboard operation
injectable copied to clipboard

How pass parameter to @singleton/lazysingleton?

Open Elendiar opened this issue 3 years ago • 3 comments

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...

Elendiar avatar Apr 27 '21 06:04 Elendiar

Use @factoryParam annotaion. See here

mozochek avatar Apr 28 '21 07:04 mozochek

Use @factoryParam annotaion. See here

But isnt it for factory? I need it for singleton, for same instance over app. Would it work ?

Elendiar avatar Apr 30 '21 13:04 Elendiar

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.

pitazzo avatar Aug 03 '22 07:08 pitazzo

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

github-actions[bot] avatar Mar 03 '23 08:03 github-actions[bot]