Re: Can @SpringBeans be optional?
Yeah, I read your post again after I sent that. You weren't necessarily saying that it was a DI-only trick. I do agree with you that it's the way to go. The Null Object Pattern would be perfect for this situation (I thought the exact same thing when I read the question). On Tue, Nov 24, 2009 at 7:59 AM, Loritsch, Berin C. wrote: > Understood. Just introducing it as a possibility. > > -Original Message- > From: James Carman [mailto:jcar...@carmanconsulting.com] > Sent: Monday, November 23, 2009 3:40 PM > To: users@wicket.apache.org > Subject: Re: Can @SpringBeans be optional? > > That's not a dependency injection thing. It's a "design pattern" > called the "Null Object" pattern. > > On Mon, Nov 23, 2009 at 12:38 PM, Loritsch, Berin C. > wrote: >> Technically speaking from the Dependency Injection koolaid doctrine, the >> best way to solve the problem is to have a "null" implementation of your >> service that does nothing. The code you are writing doesn't have to >> have complex if/else logic as it's able to assume the service is always >> there. The null implementation is wired in for the app that doesn't use >> it. >> >> Alternatively, create your accessor (getRememberMeService()) in the >> session that will access the ApplicationContext itself. It will >> determine if the bean exists or not and return the appropriate value. >> Since it allows for lazy initialization, it also addresses any issues >> from the ApplicationContext not being set up in time during unit >> testing. >> >> -Original Message- >> From: Anthony DePalma [mailto:fatef...@gmail.com] >> Sent: Monday, November 23, 2009 6:47 AM >> To: users@wicket.apache.org >> Subject: Can @SpringBeans be optional? >> >> Often with spring I give some of my services extra features if they are >> configured in the xml for it, but otherwise if they are null they are >> simply >> ignored. I'm running into an issue with my websession, that one of my >> apps >> can use the RememberMeService but another cannot. However, I'd like to >> have >> one abstractwebsession they can share, but unfortunately I'll get an >> exception when starting the app without the rememberMeService defined in >> the >> xml. It wouldn't make sense to define one to satisfy the error. >> >> The only solution I had so far was to inject it into the application >> class, >> where i can do so without @springbeans and thus a service can be null, >> but >> is there any way I can configure springbeans to not throw an error on >> startup for optional services? >> >> - >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
RE: Can @SpringBeans be optional?
Understood. Just introducing it as a possibility. -Original Message- From: James Carman [mailto:jcar...@carmanconsulting.com] Sent: Monday, November 23, 2009 3:40 PM To: users@wicket.apache.org Subject: Re: Can @SpringBeans be optional? That's not a dependency injection thing. It's a "design pattern" called the "Null Object" pattern. On Mon, Nov 23, 2009 at 12:38 PM, Loritsch, Berin C. wrote: > Technically speaking from the Dependency Injection koolaid doctrine, the > best way to solve the problem is to have a "null" implementation of your > service that does nothing. The code you are writing doesn't have to > have complex if/else logic as it's able to assume the service is always > there. The null implementation is wired in for the app that doesn't use > it. > > Alternatively, create your accessor (getRememberMeService()) in the > session that will access the ApplicationContext itself. It will > determine if the bean exists or not and return the appropriate value. > Since it allows for lazy initialization, it also addresses any issues > from the ApplicationContext not being set up in time during unit > testing. > > -Original Message- > From: Anthony DePalma [mailto:fatef...@gmail.com] > Sent: Monday, November 23, 2009 6:47 AM > To: users@wicket.apache.org > Subject: Can @SpringBeans be optional? > > Often with spring I give some of my services extra features if they are > configured in the xml for it, but otherwise if they are null they are > simply > ignored. I'm running into an issue with my websession, that one of my > apps > can use the RememberMeService but another cannot. However, I'd like to > have > one abstractwebsession they can share, but unfortunately I'll get an > exception when starting the app without the rememberMeService defined in > the > xml. It wouldn't make sense to define one to satisfy the error. > > The only solution I had so far was to inject it into the application > class, > where i can do so without @springbeans and thus a service can be null, > but > is there any way I can configure springbeans to not throw an error on > startup for optional services? > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Can @SpringBeans be optional?
That's not a dependency injection thing. It's a "design pattern" called the "Null Object" pattern. On Mon, Nov 23, 2009 at 12:38 PM, Loritsch, Berin C. wrote: > Technically speaking from the Dependency Injection koolaid doctrine, the > best way to solve the problem is to have a "null" implementation of your > service that does nothing. The code you are writing doesn't have to > have complex if/else logic as it's able to assume the service is always > there. The null implementation is wired in for the app that doesn't use > it. > > Alternatively, create your accessor (getRememberMeService()) in the > session that will access the ApplicationContext itself. It will > determine if the bean exists or not and return the appropriate value. > Since it allows for lazy initialization, it also addresses any issues > from the ApplicationContext not being set up in time during unit > testing. > > -Original Message- > From: Anthony DePalma [mailto:fatef...@gmail.com] > Sent: Monday, November 23, 2009 6:47 AM > To: users@wicket.apache.org > Subject: Can @SpringBeans be optional? > > Often with spring I give some of my services extra features if they are > configured in the xml for it, but otherwise if they are null they are > simply > ignored. I'm running into an issue with my websession, that one of my > apps > can use the RememberMeService but another cannot. However, I'd like to > have > one abstractwebsession they can share, but unfortunately I'll get an > exception when starting the app without the rememberMeService defined in > the > xml. It wouldn't make sense to define one to satisfy the error. > > The only solution I had so far was to inject it into the application > class, > where i can do so without @springbeans and thus a service can be null, > but > is there any way I can configure springbeans to not throw an error on > startup for optional services? > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
RE: Can @SpringBeans be optional?
Technically speaking from the Dependency Injection koolaid doctrine, the best way to solve the problem is to have a "null" implementation of your service that does nothing. The code you are writing doesn't have to have complex if/else logic as it's able to assume the service is always there. The null implementation is wired in for the app that doesn't use it. Alternatively, create your accessor (getRememberMeService()) in the session that will access the ApplicationContext itself. It will determine if the bean exists or not and return the appropriate value. Since it allows for lazy initialization, it also addresses any issues from the ApplicationContext not being set up in time during unit testing. -Original Message- From: Anthony DePalma [mailto:fatef...@gmail.com] Sent: Monday, November 23, 2009 6:47 AM To: users@wicket.apache.org Subject: Can @SpringBeans be optional? Often with spring I give some of my services extra features if they are configured in the xml for it, but otherwise if they are null they are simply ignored. I'm running into an issue with my websession, that one of my apps can use the RememberMeService but another cannot. However, I'd like to have one abstractwebsession they can share, but unfortunately I'll get an exception when starting the app without the rememberMeService defined in the xml. It wouldn't make sense to define one to satisfy the error. The only solution I had so far was to inject it into the application class, where i can do so without @springbeans and thus a service can be null, but is there any way I can configure springbeans to not throw an error on startup for optional services? - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Can @SpringBeans be optional?
Define a getter for your service that returns null by default, and in your Spring enabled session return the injected bean. Martijn On Mon, Nov 23, 2009 at 12:46 PM, Anthony DePalma wrote: > Often with spring I give some of my services extra features if they are > configured in the xml for it, but otherwise if they are null they are simply > ignored. I'm running into an issue with my websession, that one of my apps > can use the RememberMeService but another cannot. However, I'd like to have > one abstractwebsession they can share, but unfortunately I'll get an > exception when starting the app without the rememberMeService defined in the > xml. It wouldn't make sense to define one to satisfy the error. > > The only solution I had so far was to inject it into the application class, > where i can do so without @springbeans and thus a service can be null, but > is there any way I can configure springbeans to not throw an error on > startup for optional services? > -- Become a Wicket expert, learn from the best: http://wicketinaction.com Apache Wicket 1.4 increases type safety for web applications Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0 - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Can @SpringBeans be optional?
not right now. you can always file an rfe to add something like @SpringBean(optional=true) -igor On Mon, Nov 23, 2009 at 3:46 AM, Anthony DePalma wrote: > Often with spring I give some of my services extra features if they are > configured in the xml for it, but otherwise if they are null they are simply > ignored. I'm running into an issue with my websession, that one of my apps > can use the RememberMeService but another cannot. However, I'd like to have > one abstractwebsession they can share, but unfortunately I'll get an > exception when starting the app without the rememberMeService defined in the > xml. It wouldn't make sense to define one to satisfy the error. > > The only solution I had so far was to inject it into the application class, > where i can do so without @springbeans and thus a service can be null, but > is there any way I can configure springbeans to not throw an error on > startup for optional services? > - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org