iosobjective-cdependency-injectiontyphoon

Typhoon auto-inject assembly by protocol


I'm having a problem with correctly acquiring an assembly with auto-injection macros. For example:

@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

Then trying to use it in business logic file:

@interface MyStuff ()

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

@end

But getting the "No components defined which satisify type" error (btw there is a typo), because assembly got registered as TyphoonInjectionDefinition with class NSObject

Is it even possible to do what I'm doing?


Solution

  • You can inject the assembly itself, to act as a factory or provider, using this approach. This is an explicit wiring.

    I don't believe that auto-wiring works for assembly protocols, however you may raise a feature request if that is of interest.