Skip to content
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

New Auto-wiring API #252

Closed
alexgarbarev opened this issue Sep 11, 2014 · 6 comments
Closed

New Auto-wiring API #252

alexgarbarev opened this issue Sep 11, 2014 · 6 comments

Comments

@alexgarbarev
Copy link
Contributor

Today I intoroduced new API for auto-wiring. (I want to remove old one)
It's called auto-injection (to avoid name collision with original auto-wiring)
The auto-injection API looks:

@interface AutoInjectionKnight : Knight

@property(nonatomic, strong) InjectedProtocol(Quest) autoQuest;
@property(nonatomic, strong) InjectedClass(Fort) autoFort;

@end

That's all. Typhoon will automatically inject autoQuest property by definition for protocol Quest, and inject autoFort property by definition for class Fort.

Further discussions

  • Remove old auto-wiring and do code cleanup?
  • intoroduce more flexible injection-by-type mechanism. For example it can be excluding concrete definitions from "injection-by-type" lookup (maybe just one extra property for TyphoonDefinition).

Why we need more flexible injection-by-type?
Let's look to the real example: we have webService protocol and two implementation - real and stub.
Assembly can be looks like:

- (id<WebService>)stubWebService
{
    return [TyphoonDefinition withClass:[StubWebService class]];
}
- (id<WebService>)httpWebService
{
    return [TyphoonDefinition withClass:[HttpWebService class]];
}
- (id<WebService>)webService
{
    return [TyphoonDefinition withOption:TyphoonConfig(@"webservice.offline") yes:[self stubWebService] no:[self httpWebService]];
}

So there is three definitions of same protocol. Injection-by-type will fail with exception for WebService protocol. To handle this situation appropriately, we may need to remove stubWebService and httpWebService from the lookup. Then injection-by type will find only webService definition that return right definition based on config value.

There is another work to do: [TyphoonDefinition withOption... and [TyphoonDefinition withFactory... definitions should have correct type if possible. Currently they hold [NSObject class] type as stub but this is problem when using "injection-by-type".

@jasperblues
Copy link
Member

Great work. This is much better than the old auto-wiring. I think its fairly safe to remove the old feature immediately.

I'm not sure if its appropriate or possible for us, but DI frameworks in other languages include a qualifier attribute for cases where by type injection is not possible:

//Disambiguate and force Typhoon to inject the stub web service
@property(nonatomic, strong) InjectedProtocol(@selector(stubWebService), WebService) webService

I can see my self using this for view controllers. Another place where I would particularly like to use it is in Integration tests - so instead of setting up a factory, and pulling components for integrations tests, we could just:

  • Declare the assemblies (perhaps reference a reusable list, as most tests will use the same. therefore if that list changes, only need to update one place)
  • Declare a property to participate in the integration test using the above style.

@jasperblues
Copy link
Member

I'll update the docs over the weekend.

@jasperblues
Copy link
Member

Fixes #189 ?

@alexgarbarev
Copy link
Contributor Author

#189 - yes, it's fixed.

@fatuhoku
Copy link
Contributor

The old documentation for Autowiring is still over at https://github.com/typhoon-framework/Typhoon/wiki/Autowiring and needs removing. It confused me for a good while!

@jasperblues
Copy link
Member

@fatuhoku sorry about that. Will update today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants