Search code examples
dependency-injectioncastle-windsorioc-containerspring.netcastle

Can I use Ioc pattern to achieve the following goal


I have two classes implemented the same static methods like the following,

Class A
{
  static OpB(); 
}

Class B
{
  static OpB();
}

Can I use Ioc pattern to switch ClassA and ClassB using the configuration? Or any workaround or suggestions?


Solution

  • The IoC pattern pretty much prohibits you from using static methods because it focuses on creating instances of a type (service). Static methods are not instance methods, so an IoC container would give you an instance but you can't call a static method on an instance.

    If it's possible to drop the static qualifier on the OpB() method you'll be able to do what you want using IoC.