-
Notifications
You must be signed in to change notification settings - Fork 143
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
How to provide factoryParam to nested classes? #471
Comments
I have a similar issue. I have a logger that I pass to a lot of my classes. But this logger is registered as a factory, so each class has it's own logger. This factory has a String parameter to identify the logger for each class. But when a class has a dependency to the logger, I cannot pass this argument in the getIt. @named
@Injectable(as: Interface)
class MyClass implements Interface {
MyClass(this.logger);
final Logger logger;
}
@injectable
class Logger {
const Logger(@factoryParam this.context);
final String context;
} This generates: gh.factoryParam<_i1055.Logger, String, dynamic>(
(
context,
_,
) => _i629.Logger(context),
);
gh.factory<_i630.Interface>(
() => _i641.MyClass(
logger: gh<_i1055.Logger>(),
),
instanceName: 'MyClass',
); |
I created a solution that looks like this
|
Oh yeah nice approach @ChaserVasya. Another solution I found is: You can create a module for that Bloc and pass the Interactor that you want there: @module
abstract class BlocProvider {
@injectable
Bloc getBloc(@factoryParam Id locationId) => Bloc(getIt<Interactor>(param1: locationId));
} Then you can use it as you would normally: final bloc = getIt<Bloc>(); |
Solution: Create Interactor by hand, like in my example
These are not strict rules. This is just my experience |
I have next structure:
I want to call something like
getIt<Bloc>(param1: locationId)
, where locationId will be provided toInteractor
. How to do this with Dependency Injection principe?The text was updated successfully, but these errors were encountered: