Is there any possibility in Typhoon to return a an instance in the assembly file ?
I would like to inject a reference of AFHTTPRequestOperationManager
and then setting both the response and request serializer.
I imagine I can do something like this :
- (AFHTTPRequestOperationManager*) httpRequestManager{
return [TyphoonDefinition withClass:[AFHTTPRequestOperationManager class] configuration:^(TyphoonDefinition * definition){
[definition useInitializer:@selector(initWithBaseURL:) parameters:^(TyphoonMethod * initializer){
NSURL * baseURL = [NSURL URLWithString:kPBAuthenticatorBaseURL];
[initializer injectParameterWith:baseURL];
}];
[definition performAfterInjections:@selector(setResponseSerializer:) parameters:^(TyphoonMethod * initializer){}];
[definition performAfterInjections:@selector(setRequestSerializer:) parameters:^(TyphoonMethod * initializer){}];
}];
}
Is there no simple option to return an instance like this :
- (AFHTTPRequestOperationManager*) httpRequestManager{
AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
//Do some stuff to register it in the graph object --> HELP?
}
Is this approach wrong ?
It's currently possible to inject inline a simple object to an initializer, property or method.
It's not currently possible to declare a method that returns a simple object, and have that participate in the assembly. The reasons are:
It would be simple to relax the rule requiring all assembly methods to return a TyphoonDefinition. This would allow injecting the object returned by such a method as a dependency in other definitions, bearing in mind that it would not participate in Typhoon's scope pool.
Having such an instance automatically registered in the container would also be possible, though more involved. It would be necessary to agree on which implicit scope such an object has.