On 2/26/07, Konstantin Priblouda <[EMAIL PROTECTED]> wrote:
> Using these key objects is more verbose than using > annotations with Guice. Not necessarily. There are no references to keys in my code, only in container buildup. And only in cases where this is necessary.
My point still holds true--Pico requires more code than Guice. And annotation introduces explicit dependency to
framework - kind of uncool.
It's a tradeoff--I'll take easier maintainability and more concise code. If I choose to not to provide such constructor -
then container can not instantiate this component - there will be an ugly telling you to provide dependency.
When does Pico give you this error? Guice gives you a pretty message at startup as opposed to runtime. It even points you to the class and place where you bound it. ------------%<---------------
<!-- security and user management components --> <implementation key="securitySession" class="org.nanocontainer.persistence.hibernate.FailoverSessionDelegator"> <dependency key="userSessionFactory"/> </implementation> <implementation key="securityLifecycle" class="org.nanocontainer.persistence.hibernate.SessionLifecycle"> <dependency key="securitySession"/> </implementation> <!-- user manager --> <implementation key="userManager" class="de.jtec.user.hibernate.HibernateUserManager"> <dependency key="securitySession"/> <dependency key="hasher"/> </implementation> --------------%<----------------
It's difficult to say exactly because the example is slightly incomplete, but the equivalent of this in Guice is: bind(Session.class) .annotatedWith(Secure.class) .to(FailoverSessionDelegator.class); Then apply "@Inject @Secure" wherever you want a secure Session. You can obviously reuse the @Secure annotation elsewhere, too. Now any WW2/S2 action wishing to have reference to
UserManager needs to declare it as constructor parameter.
Guice's Struts 2 plugin injects interceptors and results, too. Guice also supports scoping using annotations. For example, you can apply @SessionScoped to an action and it will be stored in the session. PS: is project space on code.google.com available only
for employees or also for mere mortals?
Google Code is open to anyone! Bob