2

Seems to be a very basic question, but I can't find the answer (probably I'm thinking in the wrong direction):

My services are defined in a YML file.

PurchaseService:
class: Application_Service_Doctrine_PurchaseService  
calls:
- [ setPurchaseRepository, [ @purchase.repository] ]

purchase.repository:      
class: Application_Repository_Doctrine_PurchaseRepository

archive.repository:      
class: Application_Repository_Doctrine_ArchiveRepository

In a certain case I want to inject archive.repository instead of purchase.repository. How? (Note: I'm not using the complete Symfony2 framework, just the DI Container within a Zend Framework project)

1
  • In which case do you want to switch ? Commented Nov 8, 2011 at 21:53

1 Answer 1

1

You could just define the service under a second name?

ArchiveService:
  class: Application_Service_Doctrine_PurchaseService
  calls:
    - [ setArchiveRepository, [@archive.repository] ]

Then your client code would surely know which Service it needed? You could farm out which service to pull from the DIC into a factory class (or use a control statement, whatever suits your needs)?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.