Skip to main content

Google Guice vs. PicoContainer for Dependency Injection



My team is researching dependency injection frameworks and is trying to decide between using Google-Guice and PicoContainer.





We are looking for several things in our framework:





  1. A small code footprint - What I mean by a small code footprint is we don't want to have dependency injection code litter everywhere in our code base. If we need to refactor down the road, we want it to be as easy as possible.



  2. Performance - How much overhead does each framework have when creating and injecting objects?



  3. Ease of use - Is there a large learning curve? Do we have to write mounds of code to get something simple working? We want to have as little configuration as possible.



  4. Community size - Larger communities usually means that a project will continue to be maintained. We don't want to use a framework and have to fix our own bugs ;) Also any questions we have along the way can (hopefully) be answered by the framework's developer/user community .







Comparisons of the two frameworks against the listed criteria would be greatly appreciated. Any personal experiences that help to compare the two would also be extremely helpful.





Disclaimer: I'm fairly new to dependency injection so excuse my noob-ness if I asked a question that isn't pertinent to this discussion.


Comments

  1. You may want to include Spring in your list of Dependency Injection frameworks you are considering. Here are some answers to your questions:

    Coupling to the framework

    Pico - Pico tends to discourage setter injection but other than that, your classes don't need to know about Pico. It's only the wiring that needs to know (true for all DI frameworks).

    Guice - Guice annotations will appear in your code. The argument that the Guice guys use is that without a Guice annotation processor running, these shouldn't have an impact if you decide to use a different framework. You may still require the Guice jar files, though (certainly to compile).

    Spring - Spring aims to allow you to avoid any mention of the Spring framework in your code. Because they do have a lot of other helpers / utilities etc. the temptation is pretty strong to depend on Spring code, though.

    Performance

    Pico - I'm not too familiar with the speed characteristics of Pico

    Guice - Guice was designed to be fast and the comparison mentioned in the reference has some numbers. Certainly if speed is a primary consideration either using Guice or wiring by hand should be considered

    Spring - Spring can be slow. There has been work to make it faster and using the JavaConfig library should speed things up.

    Ease of use

    Pico - Simple to configure. Pico can make some autowire decisions for you. Not clear how it scales to very large projects.

    Guice - Simple to configure, you just add annotations and inherit from AbstractModule to bind things together. Scales well to large projects as configuration is kept to a minimum.

    Spring - Relatively easy to configure but most examples use Spring XML as the method for configuration. Spring XML files can become very large and complex over time and take time to load. Consider using a mix of Spring and hand cranked Dependency Injection to overcome this.

    Community Size

    Pico - Small

    Guice - Medium

    Spring - Large

    Experience

    Pico - I haven't had much experience with Pico but it is not a widely used framework so it will be harder finding resources.

    Guice - Guice is a popular framework and its focus on speed is welcome when you've got a large project that you're restarting a lot in development. I have a concern about the distributed nature of the configuration i.e. it's not easy to see how our whole application is put together. It's a bit like AOP in this respect.

    Spring - Spring is usually my default choice. That said, the XML can become cumbersome and the resulting slowdown annoying. I often end up using a combination of hand crafted Dependency Injection and Spring. When you actually need XML based configuration, Spring XML is quite good. Spring also put a lot of effort into making other frameworks more Dependency Injection friendly which can be useful because they often use best practice when doing so (JMS, ORM, OXM, MVC etc.).

    References


    Pico
    Guice
    Spring
    Spring / Guice / Pico comparison
    Another Spring / Guice performance comparison

    ReplyDelete
  2. The answer put up by jamie.mccrindle is actually pretty good, but I'm left confused why Spring is the default choice when it's pretty clear that superior alternatives (both Pico and Guice) are available. IMO Spring's popularity has reached it's peak and now it's currently living off the generated hype (along with all the other "me too" Spring sub projects looking to ride the Spring bandwagon).

    Spring's only real advantage is community size (and quite frankly, due to the size and complexity, it's needed), but Pico and Guice don't need a huge community because their solution is much cleaner, more organized, and more elegant. Pico seems more flexible than Guice (you can use annotations in Pico, or not--it's extremely efficient).
    (Edit: Meant to say it's extremely flexible, not that it isn't also efficient.)

    Pico's tiny size and lack of dependencies is a MAJOR win which shouldn't be understated. How many megs do you need to download to use Spring now? It's a kludgy-mess of huge jar files, with all it's dependencies. Intuitively thinking, such an efficient and "small" solution should scale and perform better than something like Spring. Is Spring's bloat really going to make it scale better? Is this bizarro world? I wouldn't make assumptions that Spring is "more scalable" until that's proven (and explained).

    Sometimes creating something good (Pico/Guice) and then keeping your HANDS OFF of it instead of adding bloat and kitchen sink features with endless new versions really does work out...

    ReplyDelete
  3. NOTE: This is more of a comment/rant than an answer

    PicoContainer is great. I'd switch back to it if they'd just fix their web sites. It's really confusing now:


    http://picocontainer.org/ which is the most recent, but many pages have formatting issues and a few pages don't work at all. It looks like the pages were auto-converted from the older content.
    http://picocontainer.codehaus.org/ Which seems frozen in time at version 2.10.2 - It would be really nice if the pages said something like "hey, you're looking at an old web site!"
    http://docs.codehaus.org/display/PICO/Home - A confluence wiki that documents v 1.x, but it doesn't say that anywhere on the pages!


    I'm using Guice 2.x now, even though it's bigger, and it has fewer features. It was just much easier to find the documentation, and it's user group is very active. However, if the direction of Guice 3 is any indication, it looks like Guice is starting to bloat, just like Spring did way back in the early days.

    Update: I posted a comment to the Pico Container folks and they've made some improvements to the web site. Much better now!

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex