jeudi 25 mai 2017

Dependency Injection vs Abstract Factory - choosing the right pattern

I'm developing tool that migrates issues from old to new issue tracking system. I have separated everything with interfaces, but I'm not sure what's the best way to glue it back together. I have 3 dependencies, that require runtime data:

  • INewSystemClient - client to connect to new system
  • IRetryStrategy - handles timeouts and retries
  • IMigrationSettings

These 3 dependencies are dependencies of many others. I couldn't figure out other way to glue everything, than registering these 3 as singletons (via DI container). I also know, that singletons are considered a bad pattern, so I'm considering switching to abstract factory.

Example relationship which forced me to use singleton:

  • Dependency1(INewSystemClient client, ...) // constructor for Dependency1
  • Dependency2(INewSystemClient client, ...) // constructor for Dependency2

INewSystemClient requires runtime data like user, pw, host etc.

Should I switch to abstract factory and make factory create objects instead of DI container?

Aucun commentaire:

Enregistrer un commentaire