atomicobject/objection — Issue #13: Add qualifiers when registering/binding and getting objects
Author: augustj
Created: 2011-11-03 16:39:28+00:00
State: open

Sometimes you might want to wire up two instances of the same Protocol (or Class). They might be the same implementation with different configuration, or they might be different implementations.

For example, you might have a protocol that fetches movie titles. One instance might point to a database that has "Comedy" and another that has "Action". Or they might point to different servers.

Then you could bind them in a module like this:

[self bind:comedy toProtocol:@protocol(MovieSource) withQualifier:@"comedy"];
[self bind:action toProtocol:@protocol(MovieSource) withQualifier:@"action"];

There could be additional register macros that take NSString qualifiers too.

Then manually get them like this:

id comedy = [injector getObject:@protocol(MovieSource) withQualifier:@"comedy"];

Not sure what the additional requires macros would look like.