Thursday, October 18, 2007

You can use Spring Framework to inject the service or use the cover:

1. Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
1.1). Add the UserDirectoryService bean to the bean for YourAppClass


<bean id="org.sakaiproject.yourapp.logic.YourAppClass"
class="org.sakaiproject.yourapp.logic.impl.YourAppClassImpl">
<property name="userDirectoryService"
ref="org.sakaiproject.user.api.UserDirectoryService" />
</bean>


1.2). Add a variable and setter to YourAppClass to use the service in like so:

private UserDirectoryService userDirectoryService;
public void setUserDirectoryService(UserDirectoryService userDirectoryService) {
this.userDirectoryService = userDirectoryService;
}


2. Using the cover to get the service
* Note: This is not the recommended method, you should be using Spring to inject the service
2.1). Setup a variable to hold the instance from the cover

private UserDirectoryService userDirectoryService;


2.2). Get access to the service using the cover

userDirectoryService = org.sakaiproject.user.cover.UserDirectoryService.getInstance();






ATTENTION:: If you're using the first method, you should be sure of that your project is following sakai's structure, especially the bean's id.
I am using the second one.

No comments: