Hello Bokie, On Nov 11, 2012, at 13:40 PM, bokie <[email protected]> wrote:
> When working with the DependencyManager api, there's always a little voice > saying: where do I put this, in the init or the start, in the stop or in the > destroy, is it really that important - so, what is the spirit behind these > methods, what should we consider when answering that little voice :) There is a difference, but it will depend on your use case if this actually matters. I will try to explain this based on the "init" and "start" callbacks. The init callback is always invoked first, and as an optional parameter you can get a reference to your own Component (the one you created in the bundle activator). What this method allows you to do at this point in the life cycle is to add extra dependencies dynamically. The use case for this could for example be a component that has a dependency on some configuration. Let's say that in this configuration there is a parameter that determines if this component should depend on another service or not. In the init, you can be sure that all required dependencies are already injected, so you can read your configuration. Based on what you find, you can then add an extra dependency to your component. Now two things can happen: this extra dependency is available (or optional). In this case the component will continue initialization and the "start" will be invoked (and there you can rely on this extra dependency to also be injected). If the new dependency is not available, the component will "wait" until it is. This is also why there is a flag called "instance bound" for a dependency. You should use it here. It will ensure that this new dependency, if not available, will not immediately destroy the component again as it normally would. Long story, the take away is that in most cases, you can just use "init" or "start", but if you have dynamic components, both methods play a specific role in that process. Greetings, Marcel --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

