-
1. Re: Dynamic injection in Web Beans?
nickarls Aug 8, 2009 10:05 PM (in response to asookazian)Hmm, I'm not familiar with Spring 3 injection but since Web Beans injects proxies for normal scoped beans, you are getting the up-to-date instance at invocation time.
-
2. Re: Dynamic injection in Web Beans?
nickarls Aug 9, 2009 8:51 PM (in response to asookazian)And you could you producer fields/methods for dynamic resolution.
For the really-really dynamic version you might be able to add an annotation @Dynamic at the injection point and modify the proxy method handler to re-lookup before invoking ;-)
-
3. Re: Dynamic injection in Web Beans?
pmuir Aug 9, 2009 11:51 PM (in response to asookazian)I don't get this? The proxy always looks up the most recent version.
Arbi, what is
dynamic injection
? -
4. Re: Dynamic injection in Web Beans?
nickarls Aug 10, 2009 8:25 AM (in response to asookazian)I would guess the following scenario:
- you have and interface Foo
- and a class Bean1 that implements Foo
- and a class BeanUsage that injects a field on interface Foo (instance of Bean1)
- and you runtime add a class Bean2 that implements Foo (higher precedence than Bean1)
- BeanUsage field would now be an instance of Bean2
as currently the injection point get wired at creation time to a certain bean (and the proxy makes sure we're hooked up the current instance of that bean) but there is no switching of the bean in question.
but producer fields/methods can be used to work around this, right?
-
5. Re: Dynamic injection in Web Beans?
asookazian Aug 10, 2009 5:46 PM (in response to asookazian)
Pete Muir wrote on Aug 09, 2009 23:51:
I don't get this? The proxy always looks up the most recent version.
Arbi, what isdynamic injection
?From SiA:
If you’re familiar with Spring, you might be tempted to use static injection
as the primary means of wiring your components together. I don’t
recommend that you standardize on this approach. For one, it requires a
ridiculous amount of XML. In general, XML should be reserved for infrastructure
configuration. Although not applicable in this example, you
also must ensure that you aren’t injecting a component from a shorterterm
scope into a component in a longer-term scope, as it results in
scope impedance. It’s much cleaner, safer, and Seam-esque to wire components
together using dynamic injection, declared using the @In annotationSo dynamic injection is injection that occurs more than once. It occurs every time a business method is called on that component. Static injection occurs only once in the lifetime of the compoment, either via setter method or constructor.
Reading my initial post, it has more to do with Spring that Seam/WB but I guess I'll re-word it so it's applicable to this forum:
If WB/Seam3 uses dynamic injection (most likely it does - at least Seam 2.x does), what would happen if it was designed with static injection instead? What limitation(s) would that bring to our apps? I'm just wondering how Spring apps deal with this stale injection problem on a continual basis and if it is a problem in a stateful or stateless architecture or both.
I mean, if you can deal with static injection, that means less interceptions and injections than dynamic DI and less overhead per life of a component and overall better performance, no?
Here's my point:
What if we wanted static DI sometimes and dyamic DI sometimes in the same component or different components? Mix and match as the use case requires to improve performance. Or is the performance hit negligible with dynamic DI? Not all use cases in a Seam app are modeled using stateful components, are they? What about a report, for example, or a web service consumption/client for a credit card validator service, etc?