I am have a confusion on how to go about with above scenario in Spring (dependency injection context)
class Login {
String username;
String password;
UserAuthService userAuth;
/*
assume getter and setter
methods for above private
properties here
*/
}
UserAuthService is a interface which has a boolean method validate(String username , String password);
It is implemented by BasicAuthService, LDAPAuthService, MockBasicAuthService, MockLDAPAuthService; Also Assume that BasicAuthServie has a property serverAddress , as string which has the IP address of authentication server, same with LDAPAuthService.
Context of my Question is Dependency Injection and Spring ,
I understood that based on beanconfig file Spring('s IOC) will inject one of the concrete implementation of UserAuthService.
1 . In beanconfig file we can only configure one ref say ( ) Scenario: Suppose in UI user has a dropdown to select BasicAuth / LDAPAuth . User have selected LDAPAuth , how to deal with this case in spring ? since we have hardwired ref="beanIdBasicAuthService" in beanconfig file). Is there a way to dynamicaly change the ref ?
2 . Little more complex ( assume IT admin or so) , UI is now providing option to select the address of the authentication server (which is a property in the Basic/LDAP Auth Service Class) Again in beanconfig file we would have hardwired the properties. How to go about dynamicaly changing it in spring ? (other than explicitly getting the injected bean and calling setterMethod)
These scenarios are a bit confusing to me. Can someone please explain this ?