0

Once I read in some google document about coding guidelines that every new instance of a class should go from a factory class, and I use SwiftSuspenders for it.

Now my question is, is it possible to create a new instance of an object that requires constructor parameters using SS's dependency injection?

ThanksBro
  • 911
  • 1
  • 7
  • 20

1 Answers1

1

Yes, Swiftsuspenders fully supports constructor injection.

You can either inject into a field (or a method or another constructor) requiring an instance of your class, or you can use injector.getInstance to directly query the injector for an instance that's created using the injector's mappings.

  • Well, I think I don't understand. Can you get an instance of a class that requires parameter on construction and how would you do it? Can you post code example please. If I use injector.getInstance i get an error that I am missing a constructor parameter of course. – ThanksBro Feb 15 '13 at 17:18
  • 1
    @MatejŠimunić If the constructor parameter is of a type which is mapped in the injector, it will be injected. Otherwise not, obviously. – Creynders Feb 20 '13 at 17:35