Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No register type error #118

Closed
oscarshaitan opened this issue Oct 16, 2020 · 16 comments
Closed

No register type error #118

oscarshaitan opened this issue Oct 16, 2020 · 16 comments

Comments

@oscarshaitan
Copy link

I get this error

No type XUseCase is registered inside GetIt.
 Did you forget to pass an instance name? 
(Did you accidentally do  GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
did you forget to register it?)

get it dont find the XUsCase but is already registered

sl.registerLazySingleton<XUseCase >(() => XUseCase (sl()));

@escamoteur
Copy link
Collaborator

looks good to me, what is the constructor of XUseCase doing? can you show me the code where you get the exception?

@oscarshaitan
Copy link
Author

oscarshaitan commented Oct 16, 2020

class XUseCase {
  final XRepository repository;

  XUseCase (this.repository);

  Future<Either<Failure, dynamic>> call(String param1, String param2) async {
    return repository.run(param1, param2);
  }
}

is to simple usecase
that use case is needed on a bloc an I call the use case with
XUseCase xUsecase = sl.get<XUseCase>();

@oscarshaitan
Copy link
Author

and was working fine I have at least 15 types registered the only thing new is I update to get_it: ^5.0.1

@escamoteur
Copy link
Collaborator

What should this here do sl()?

@oscarshaitan
Copy link
Author

sorry thats my get_it instance :D
final sl = GetIt.instance..allowReassignment = true;

@escamoteur
Copy link
Collaborator

yeah but you call it while passing to the constructor:
sl.registerLazySingleton<XUseCase >(() => XUseCase (sl()));

@oscarshaitan
Copy link
Author

this
sl.registerLazySingleton<XUseCase >(() => XUseCase (sl()));
in on the setup just like the guide.
in this case that bloc is not provide by the get_it I'm getting the usecase just when I needed not on the constructor

@escamoteur
Copy link
Collaborator

yeah, so you are expecting that the sl() returns you a registered instance of XRepository ? could it be that the constructor of XRepository tries to access `XUsecase'

@oscarshaitan
Copy link
Author

no, the repo dont have any instance of sl or the usecase

@oscarshaitan
Copy link
Author

an yesh Im specting sl return a Xrpository tha tis also registered
sl.registerLazySingleton<XRepository >(() => XRepository (sl()));

@oscarshaitan
Copy link
Author

also tht repository dependecy is registered too. was working just fine until yesterday that I update to get_it: ^5.0.1 also I made a full clean and restaert everything.
btw is happening only on ios

@escamoteur
Copy link
Collaborator

I recommeds always use sl() which is better to read.

Now, that seems pretty weird that it only happens on iOS because get_it doesn't use any system functions.

could it be that it's a timing issue? that somehow on iOS a part of code gets executed that tries to access XUsecase before it it registered?
Did you check in the stack trace when the exception happens where the sl() is called?

@oscarshaitan
Copy link
Author

I dont think is the timing cuz all those register are happening before the runApp() call so is weird indeed and more wierd that os happening only on ios

import 'injection_container.dart' as di;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  di.init();

  runApp(MyApp());
}

@escamoteur
Copy link
Collaborator

would you mind joining me in a zoom call that I can look at your project?
That is honestly too weird.

@oscarshaitan
Copy link
Author

sure!

@oscarshaitan
Copy link
Author

@escamoteur I clean flutter reset/invalidate cache and now is working Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants