Blog uživatele petr
Scala dependency injection
Vložil/a petr, Ne, 15/03/2009 - 13:33Recently I've discovered Scala, and being a functional languages fan I enjoyed many great Scala's features. I decided to use it in our projects and one of the things I wanted to learn is how to do dependency injection in some elegant way.
After searching for a while I stumbled upon [url=http://jonasboner.com/]Jonas Bonér's[/url] great article [url=http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di.html]Real-World Scala: Dependency Injection (DI)[/url]. I learned a lot about Scala from the article, as well as about dependency injection. But I wasn't comfortable with one thing in his approach: The dependencies of a component are fixed in such a way that it's not possible to have two different components providing the same service, but each depending on different sub-components. (Or at least I wasn't able to figure it out.). For example, let's say that I have a service that returns a list of users and I want to implement it by two interchangeable components: one that reads users from a database and another that reads users from a file. So the former should depend on a database provider subcomponent, while the other one on a subcomponent providing access to a file-system. However, it's not very difficult to refine the idea a bit further to gain (IMHO) even more flexible architecture.
Example how to construct a MHT (AKA MHTML) file in Java using JavaMail API
Vložil/a petr, So, 08/03/2008 - 16:23String) with an image, which
* is pulled from a file.
*
* Requires mail.jar in the classpath (and also Java
* Activation Framework if JDK version is less than 1.6).
*/