ios - 台风自动注入(inject)程序集

标签 ios objective-c dependency-injection typhoon

我在使用自动注入(inject)宏正确获取程序集时遇到问题。例如:

@protocol IFormatterProvider <NSObject>

- (id)statusTextFormatter;

@end

@interface MyAssembly : TyphoonAssembly <IFormatterProvider>
@end

@implementation MyAssembly

- (id <IFormatterProvider>)formatterProvider
{
    return [TyphoonDefinition with:self]; // First guess
}

- (id)statusTextFormatter
{
    // impl
}

@end

然后尝试在业务逻辑文件中使用它:

@interface MyStuff ()

@property (nonatomic, strong) InjectedProtocol(IFormatterProvider)formatterProvider;

@end

但是得到“没有定义满足类型的组件”错误(顺便说一句,有一个拼写错误),因为程序集被注册为 TyphoonInjectionDefinitionNSObject

是否有可能做我正在做的事情?

最佳答案

您可以使用 this approach 注入(inject)程序集本身,充当工厂或提供者。 .这是显式接线。

我不认为 Autowiring 适用于汇编协议(protocol),但是如果您对此感兴趣,可以提出功能请求。

关于ios - 台风自动注入(inject)程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39370421/

相关文章:

dependency-injection - 将 Unity Hook 到 Web API 过滤器属性中

ios - 在 UISplitViewController 的子类中更新 DetailViewController 的框架

objective-c - 执行 Facebook 查询时没有返回结果

ios - 在数据库中进行一系列插入后内存不会减少

c# - 使用 C# 的 Windows Phone 7 上的 NSUserDefaults 等价物是什么?

asp.net-mvc-3 - 具有由多个类实现的接口(interface)的依赖注入(inject)

ios - UIWindow 中存在 UIAlertContoller ios8

ios - 使用 Facebook 电子邮件登录未返回

ios - 如何安装 ios 应用程序并向其发送参数?

java - 是否可以将特定类型的不可变集绑定(bind)到 Guice 中的实例?