Research Log of Web Science Students

Computer Science is not simply programming

Wiring my first factory in Spring

leave a comment »

I felt the need to have only one instance of google’s user service in our app. Instatiating it in different places is clearly shotgun surgery!

I had this piece of code all over our controllers!


UserService userService = UserServiceFactory.getUserService();

The solution: instantiate it only once in the Spring Container and
inject it into all objects that need it. Like so:

<bean id="googleUserService"
         class="com.google.appengine.api.users.UserServiceFactory" 
         factory-method="getUserService">
</bean>

Sample controller that needs the user service:

<bean id="IndexController"
         class="com.hardwire.controller.IndexController">
 	<property name="userService"
                      ref="googleUserService">
         </property>
 </bean>

I am glad that went well. Sheesh I need to start blogging about our research. Nuff of the technical stuff for now.

Advertisements

Written by Jose Asuncion

August 30, 2009 at 5:33 pm

Posted in Hardwire

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: