On 2/27/07, Konstantin Priblouda <[EMAIL PROTECTED]> wrote:
Pico approach at least leaves your managed classes alone.
Right, and Guice supports both approaches (the external approach via custom providers which are roughly equivalent to Pico's external configuration). Strictly speaking, pico itself does not ofer any
externalised configuration,
Whether it's through a Java API or XML doesn't matter--it's still external configuration, and it's still code. Pico can be configured by
some java code ( like guice )
Except Pico requires more repetition.
Um, yeah. Doesn't Pico need multiple key objects? > And to apply those key > objects, don't I have to write external code where I > repeat property names, > etc.? Well, every distinct instance clearly requires own unambiguous key to be distinguished. Propety names are usually not involved.
Pico's key is equivalent to Guice's annotation except annotations require less code overall. Pico itself has no concept of scope, or better said
container is a scope of its own. As it allows conainer hierarchy, scopes are implemented by chaining containers ( and in web envirobment those containers will be assotiated with application / session / request / subscopes )
To my knowledge, Joe Walnes was the first to implement this pattern in WebWork's built in DI container. I started down that path with Guice originally, but it's not as user friendly, it didn't play nicely with session replication, and more (I don't remember the details, but we discussed this exact issue on this list awhile back). Of course you have to pay attention where your
component is being registered and if there is necessity for thread safety. And you can impose sychronization on object later by means of special wrapping component adapter (if you forgot to design your component right). I can not remember whether there is already such adapter, but if not it would have not much difference with hotswapping one.
I wouldn't recommend blindly synchronizing all method in an object--it most likely won't do the right thing. Well, but I have to place it on class source and
compile with it. And now I'm speaking about class from separate project ( i.e VelocityEngine ) - and what do I do if I need the same class in another project in different scope? PLace 2 annotations on it and then recompile and release into maven repository? And how iws guice gound to tell those 2 scopes apart? What if I need 2 instance of same class in 2 different scopes in same app? ( not that uncommon... )
Don't use annotations in this case. Specify the scope externally, like I just suggested a second time in my last email. Bob