[Building Sakai] Question about Component Manager

Matthew Jones matthew at longsight.com
Mon Jul 21 11:05:51 PDT 2014


I believe that the main reason is that if you use Spring to wire up the
components, it can be more reliable about actually determining the loading
order. If you just use the ComponentManager class, there may be cases where
you request a Service and it's not yet actually loaded, because Spring
setup your class first as it didn't know it had to set up something you
depended on first. It also makes it easier to swap that Service either for
testing or if someone just wants to use a different service than having to
change your code.

If you avoid using any of the services in your init or until the system is
fully running you would be okay. Otherwise you need to always check
ComponentManager returns a null. But it does have chance to return a null
and cause an NPE. If there is an NPE during a Spring init then tomcat won't
startup.

So it's just advice for best practice is all. There are many times in which
you can't use Spring and have to do it this way. But ideally you there are
more advantages to using Spring if possible.


On Mon, Jul 21, 2014 at 1:26 PM, Sergio Muriel <sergioame at hotmail.com>
wrote:

> Dear All,
>
> I've been wondering why I find this text everywhere in the Sakai
> documentation:
> "Using the Component Manager to get the service
>
>    - *Note:* This is not the recommended method, you should be using
>    Spring to inject the service
>
> "
>
> Is it because the Component Manager doesn't work at all for certain
> services like UserDirectoryService or DeveloperHelperService?
> It works for me when I need services like SessionManager
> or SiteService.....
>
> Thank you for any help!
>
>
> Best Regards,
> Sergio Muriel
>
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to
> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
> "unsubscribe"
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20140721/36748193/attachment.html 


More information about the sakai-dev mailing list