struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aum Strut <aum.str...@gmail.com>
Subject How to get instance of the given dependency using Container
Date Sun, 30 Sep 2012 14:33:39 GMT
Hi All,

I am working on a requirement where i need to get instance of given class
at run time using Struts2 Container and here is my Code

public class MyClass{

  private Class<? extends MyCustomClass> provider;

 public MyClass(@inject Container container){

    provider=container.getInstance();  // this is where i got strucked

 }

}

Since Provider can by anyone who extends MyCustomClass so i am not
sure before hand which implementation will be provided at run time.I
am not sure how to get instance in this case from container.

for e.g At run time there can be Either ClassA or ClassB or may be
ClassC which all extends MyCustomClass.

How can i pass this information to the container to get the instance
of the class passed at run time?


Thanks in advance

-a

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message