-
1. Re: Dependency Injection with Seam
kenclark Aug 4, 2008 5:21 AM (in response to compiledmonkey)It seems like there are a million ways to do what you want. Here is one that uses Seam Bijection. I have not actually done exactly this before but I think it should work.
1) Create an action class that outjects the Interface you are interested in and has a corresponding factory method:
public class MyAction { @Out private MyInterface myInterface; @Factory("myInterface") public String loadAllTemplates() { // Implement your loader however you like if (x) myInterface = new X(); else myInterface = new Y(); } }
2) Now inject that in any class that needs it. You can scope it appropriately based on your needs. Here is the simple injection code:
public class TargetAction { @In private MyInterface myInterface; // ... public String myAction () { // Use myInterface myInterface.doStuff(); } }
Good luck.
ken
-
2. Re: Dependency Injection with Seam
pmuir Aug 4, 2008 1:16 PM (in response to compiledmonkey)Web Beans handles this really nicely through deployment types (but that is for the future).
In the meantime, you can either use precedence if you have a distinct precedence (e.g. in a test env, always deploy test precedence over standard precedence) or only include the implementation you want in the archive/classpath.
-
3. Re: Dependency Injection with Seam
samy Apr 6, 2011 3:45 AM (in response to compiledmonkey)Ken Clark,
you can give a simple example concerning
MyInterface