-
Notifications
You must be signed in to change notification settings - Fork 268
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
Singleton auto injection #320
Comments
Found solution. @interface ViewControllerAssembly ()
@property(strong,nonatomic) CoreAssembly *coreAssembly;
@property(strong,nonatomic) ViewModelAssembly *viewModelAssembly;
@end
@implementation PMViewControllerAssembly
-(id)splashScreenViewController{
return [TyphoonDefinition withClass:[VCSplashScreen class] configuration:^(TyphoonDefinition *definition) {
[definition useInitializer:@selector(initWithNibName:bundle:) parameters:^(TyphoonMethod *initializer) {
[initializer injectParameterWith:@"SplashScreenView"];
[initializer injectParameterWith:[NSBundle mainBundle]];
}];
#Inject viewModel, but before invoke registerObject mehtod on localize manager with that view model
[definition injectProperty:@selector(viewModel) with:[_coreAssembly localizeManagerRegister:[_viewModelAssembly splashScreenViewModel]]];
}];
} @interface ViewModelAssembly ()
@property(strong,nonatomic) DataControllerAssemly *dataControllerAssemly;
@property(strong,nonatomic) CoreAssembly *coreAssemly;
@end
@implementation ViewModelAssembly
-(id)splashScreenViewModel{
return [TyphoonDefinition withClass:[VCSplashScreenViewModel class] configuration:^(TyphoonDefinition *definition) {
[definition injectProperty:@selector(backgroundImageName) with:@"pm_splash"];
[definition injectProperty:@selector(authDataController) with:[_dataControllerAssemly authDataController]];
[definition injectProperty:@selector(locationDataController) with:[_dataControllerAssemly locationDataController]];
}
@end @implementation CoreAssembly
-(id)localizeManager{
return [TyphoonDefinition withClass:[LocalizeManager class] configuration:^(TyphoonDefinition *definition) {
[definition useInitializer:@selector(manager)];
[definition setScope:TyphoonScopeLazySingleton];
}];
}
-(id)localizeManagerRegister:(id)obj{
return [TyphoonDefinition withFactory:[self localizeManager] selector:@selector(registerObject:) parameters:^(TyphoonMethod *factoryMethod) {
[factoryMethod injectParameterWith:obj];
}];
}
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. When some object injected, can Typhoon automatically also inject that object into some singleton object, on the fly?
Example:
Where core assembly is:
The text was updated successfully, but these errors were encountered: