RivaanRanawat / blog-app-clean-architecture

Clean Architecture in Flutter using Supabase, Bloc, Hive, Get_It & FpDart.
166 stars 50 forks source link

When use Singleton and when use Factory for DI #2

Open datnguyennt opened 5 months ago

datnguyennt commented 5 months ago

Hello sir, I have a concern about dependency injection with using get_it. Could you explain why you use a singleton for bloc and cubit, and factory for the other apply in your project? Thank you! https://github.com/RivaanRanawat/blog-app-clean-architecture/blob/master/lib/init_dependencies.main.dart

atvbasha commented 4 months ago

+1

sagnik-sanyal commented 3 months ago

Hello sir, I have a concern about dependency injection with using get_it. Could you explain why you use a singleton for bloc and cubit, and factory for the other apply in your project? Thank you! https://github.com/RivaanRanawat/blog-app-clean-architecture/blob/master/lib/init_dependencies.main.dart

Hi there @datnguyennt , we use singleton whenever we want to ensure that only a single instance of a class is created and there are no duplicate instances, besides factory is used to create multiple instances of a class generally scoped to a route in order to use that particular instance for achieving a particular task