0

*I am not an expert on spring or IoC - I would like to have my client app "select" different implementations of an interface based on some conditions.

I believe Spring (or other IoC containers) allow doing this, however all examples show that the concrete class is configured in some configuration file, which is not what i am after.

I would like to (somehow) allow the container to decide which implementation to choose from (based on some conditions and a given set of classes to select from).

Is this possible? ( i am pretty sure it is).

lysergic-acid
  • 19,570
  • 21
  • 109
  • 218

1 Answers1

3

You could use a factory class (it could be static or instance factory).

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • What is the benefit of using Spring then, if i need to provide my own Factory (i could write the same thing without Spring) – lysergic-acid Apr 17 '12 at 12:24
  • 2
    If you are only using spring as a factory to get objects from, you are not taking full advantage of the capabilities of the spring container, such as interception. You might be interested in reading these questions [1](http://stackoverflow.com/questions/557742/dependency-injection-vs-factory-pattern) [2](http://stackoverflow.com/questions/871405/why-do-i-need-an-ioc-container-as-opposed-to-straightforward-di-code) [3](http://stackoverflow.com/questions/2407540/what-are-the-downsides-to-using-dependency-injection). – Marijn Apr 17 '12 at 12:42