Skip to content

Raises error: not registered inside GetIt although it is #322

Closed
@ChinaeduO

Description

@ChinaeduO

Hi,
I am having a problem with the package. Inside of my injector class I am registering all my blocs, datasources etc.:

locator.registerLazySingleton<Dio>(() => Dio());
 locator.registerLazySingleton(() => const FlutterSecureStorage());
 locator.registerLazySingleton<UserRepository>(
   () => UserRepositoryImpl(secureStorageDataSource: locator()),
 );

 locator.registerLazySingleton<KIBackendDatasource>(
     () => KIBackendDatasourceImpl(dio: locator()));

 print('Is registered: ' +
     locator
         .isRegistered(instance: locator<KIBackendDatasource>())
         .toString());

 locator.registerLazySingleton<AuthenticationRepository>(
     () => AuthenticationRepositoryImpl(kiBackendDatasource: locator()));

 locator.registerLazySingleton(() => GetUserDataUseCase(locator()));

 locator.registerLazySingleton(() => AuthenticationBloc(
     authenticationRepository: locator(),
     userRepository: locator(),
     getUserDataUseCase: locator()));

But when running the code the package throws an error that says:

Object/factory with  type KIBackendDatasourceImpl is not registered inside GetIt. 
(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
Did you forget to register it?)

I have registered the KIBackendDatasourceImpl. And even if I am checking the registration with:

locator
          .isRegistered(instance: locator<KIBackendDatasource>())

It is returning true.

So is there an issue or am I doing anything wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions