-
Notifications
You must be signed in to change notification settings - Fork 268
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
Guidance on objects being instantiated before application:didFinishLaunchingWithOptions:... where, when, or how should services be set up? #308
Comments
We could debate creating a hook for this in either the - (void)typhoonWillStartUp; //for want of a better name or - (void)assemblyWillAssemble; //or something *but what I currently do is create a category on the framework class and use: * [definition performBeforeInjections:SEL]; If you wish you can use |
another options:
<-- Useful when not too much objects requiers parse at startup
<-- Harder to read and understand (implicit) but usefull when too much objects requires one dependency (for example logging system like cocoalumberjack) |
And one other existing way folks do this is create a definition that uses - (id)loggers
{
return [TyphoonDefinition withClass:[DDLog class] configuration:^(TyphoonDefinition *definition) {
[definition useInitializer:@selector(class)];
[definition injectMethod:@selector(addLogger:) parameters:^(TyphoonMethod *method) {
[method injectParameterWith:[self ttyLogger]];
}];
definition.scope = TyphoonScopeSingleton;
}];
} This definition above has singleton scope, so will be run on startup. It won't be guaranteed to run first though, so take care. (Subsequent components that depend on this could have Questions:
|
@jasperblues Thanks for the response. I'll try the latter approach out. It seems to be more consistent with other definitions. About a standard approach, I think yes, definitely. And yes, it is okay to be creative as well, only if the standard approach isn't sufficient for your needs. This sort of thing is in virtually every app. All the developer cares about is that I just want, say, Parse to be set up in my app so that I can start using it. The last thing I want is to be forced to consciously think about how to teach my fantastic Typhoon DI container to do something that normally takes 2 seconds: paste a line of code into So yes! A documented standard approach please! |
Which to people like: - (void)typhoonWillStartUp; //for want of a better name
``
or TyphoonAssembly:
```objc
- (void)assemblyWillAssemble; //or something or The way shown above using the 'class' as the initializer along with the ability to set order or instantiation? My preference is the 2nd: |
Yeah I imagine the latter is better. Parse is a dependency; and therefore falls under the remit of — guess what — a dependency injection framework like Typhoon! So I actually see that Typhoon will recommend not one, but two potential implementation options:
I would stress that both options need to be clearly documented so that the developer has a chance of picking and choosing what's suitable for them at the time. The second option is the 'correct' way to set it up, but requires knowledge of Typhoon and is premature abstraction. It's also worth saying at this point that this issue only exists if you want to inject anything into What do you think @jasperblues? |
@fatuhoku Maybe we can extend API or something... After that we could recomment that as 'correct' approach |
|
Finally I think using I prefer these two options:
|
@fatuhoku Would you like push access to help clean up the documentation? It would be really helpful, since the challenges you faced getting started with Typhoon (current features) are still fresh in mind. Meanwhile, you've been involved in discussions on future features. |
@jasperblues Yeah I'm not objected to that. I would love to contribute what I know of Typhoon in the form of documentation. I intend to slowly refactor my application to make use of it. |
@fatuhoku granted. We really appreciate your help. Its nice to meet someone who cares about good documentation. As it stands now Typhoon is helpful for folks are very familiar with Di from other languages. We'd really like if the documentation was good enough for all folks to benefit. |
Please let us know if you make changes so that we can review the technical accuracy and give feedback. |
@jasperblues Sure thing. I'll do this on a need-by-need basis. Got a slightly different focus right now! |
@fatuhoku I just faced this issue too. Cheated by hooking |
@jasperblues Ah, look at you, hooking into all those undocumented methods ;) Being creator has its perks! If you're happy with that as the solution for now I could go document it. |
I found that @implementation AppDelegate
- (instancetype)init
{
self = [super init];
if (self) {
[self setupLogging];
}
return self;
} The lifecycle is:
|
I wondered if it still might be beneficial to create the life-cycle method? This would communicate intention to folks. Alternatively we can just add API doc to init, saying it can be safely overridden. |
@alexgarbarev Fantastic. I think that has to be the most straightforward solution of all... It is pretty non-standard though. @jasperblues My vote is for documenting the use of |
Once the docs have been done, let's badge as 'Ready for Review'. After that we can close off the ticket. |
NB, if you add API docs to any Typhoon classes, and commit, they'll turn up on www.typhoonframework.org/docs/latest/api after a few minutes. |
Many services offer iOS SDKs that require the app to set the SDK up with a one-line class method call early in the application. e.g.: Parse's initialization looks like:
[Parse setApplicationId:@"<your app id>" clientKey:@"<your client key>"];
.These often go into the
-application:didFinishLaunchingWithOptions:
method of yourXXAppDelegate
.When using Typhoon, it sometimes makes sense to inject components that make use of these services. The problem is, it's possible that these components are instantiated before
-application:didFinishLaunchingWithOptions:
even has a chance to execute. For instance:So officially, where should these calls go instead?
The text was updated successfully, but these errors were encountered: