appsquickly / typhoon

Powerful dependency injection for Objective-C ✨✨ (https://PILGRIM.PH is the pure Swift successor to Typhoon!!)✨✨
https://pilgrim.ph
Apache License 2.0
2.7k stars 269 forks source link

Auto-inject assembly by protocol #529

Open Emailrus opened 8 years ago

Emailrus commented 8 years ago

Related post on SO

It might be nice to have an ability for assemblies to auto-inject themselves, for example:

@protocol IFormatterProvider <NSObject>

- (id)statusTextFormatter;

@end

@interface MyAssembly : TyphoonAssembly <IFormatterProvider>
@end

@implementation MyAssembly

- (id <IFormatterProvider>)formatterProvider 
{
    return [TyphoonDefinition with:self]; // or something similar
}

- (id)statusTextFormatter
{
    // impl
}

@end

// -------

@interface MyStuff ()

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

@end

This way we don't have to create a factory as a separate class (assembly will act as one), no need to write injectProperty stuff in assemblies (to manually inject assembly) and therefore will be no warnings about using undeclared selectors (in case of injected properties being declared in class extension).

alexgarbarev commented 7 years ago

Thats' quite easy to add. There is few ways to achieve that. (Add new kind of definition, adjust TyphoonInjectionDefinition etc..)

jasperblues commented 7 years ago

👍 I like it

jasperblues commented 6 years ago

Still interested in working on this @etolstoy ?