台风 - 获取实例而不是定义

时间:2015-11-10 16:19:54

标签: objective-c typhoon

我正在使用plist整合的台风。在一个程序集中,我需要创建一个具有如下初始化程序的实例: @selector(initWithBundleURL:moduleProvider:launchOptions:) 第二个参数moduleProvider:采用一个块,该块返回一个对象数组。我想使用台风来注入该数组中的每个对象。

- (RCTBridge *)bridgeWithModule1:(Module1 *)module1 module2:(Module2 *)module2 {
return [TyphoonDefinition withClass:[RCTBridge class] configuration:^(TyphoonDefinition *definition) {
    [definition useInitializer:@selector(initWithBundleURL:moduleProvider:launchOptions:) parameters:^(TyphoonMethod *initializer) {

        [initializer injectParameterWith:url];

        RCTBridgeModuleProviderBlock block = ^NSArray *() {
            return @[module1, module2];
        };
        [initializer injectParameterWith:block];

        [initializer injectParameterWith:nil];
    }];

    definition.scope = TyphoonScopeLazySingleton;
}];
}

上面的代码不起作用。因为module1module2在运行时是TyphoonDefinition而不是真实实例。有没有办法用台风来注入实例?

1 个答案:

答案 0 :(得分:1)

使用Typhoon,您可以使用run-time arguments的汇编接口来混合静态和运行时依赖关系。这避免了创建自定义工厂类的样板。但是,because of the way Typhoon works您无法修改定义中的运行时参数。

如果需要,请创建自定义工厂类。

  • Inject the TyphoonAssembly进入您的自定义类,以提供使用静态依赖项构建的对象。
  • 工厂方法将类似于您在装配界面上定义的方法。将静态依赖项与运行时参数混合,然后返回构建对象。