{"action":"created","issue":{"url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4442","labels_url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4442/labels{/name}","comments_url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4442/comments","events_url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4442/events","html_url":"https://github.com/silverstripe/silverstripe-framework/issues/4442","id":97567988,"number":4442,"title":"Injector factories should be passed the full service definition","user":{"login":"sminnee","id":59968,"avatar_url":"https://avatars.githubusercontent.com/u/59968?v=3","gravatar_id":"","url":"https://api.github.com/users/sminnee","html_url":"https://github.com/sminnee","followers_url":"https://api.github.com/users/sminnee/followers","following_url":"https://api.github.com/users/sminnee/following{/other_user}","gists_url":"https://api.github.com/users/sminnee/gists{/gist_id}","starred_url":"https://api.github.com/users/sminnee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sminnee/subscriptions","organizations_url":"https://api.github.com/users/sminnee/orgs","repos_url":"https://api.github.com/users/sminnee/repos","events_url":"https://api.github.com/users/sminnee/events{/privacy}","received_events_url":"https://api.github.com/users/sminnee/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-07-27T22:16:28Z","updated_at":"2015-07-29T00:08:47Z","closed_at":null,"body":"Injector factories could be more flexible if they were passed the full service definition as a 3rd argument.\r\n\r\nFor example, we could use a custom factory to do some special processing on selected `properties`. This relates to my work on #4430\r\n\r\n * Advantage: Factories can be used to tidy up confusing aspects of Injector service definition\r\n * Disadvantage: Factories could do anything, risking that we get a more divergent & confusing set of configuration approaches. We may end up with service definitions that have options other than `class`, `constructor`, `properties`, and `dependencies`.\r\n\r\nOne way to mitigate that disadvantage would be to set some guidelines for writing good factories.\r\n\r\nThe change would be trivial and I'll post a PR if I get buy-in, but I want to run it past people first."},"comment":{"url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/comments/125786296","html_url":"https://github.com/silverstripe/silverstripe-framework/issues/4442#issuecomment-125786296","issue_url":"https://api.github.com/repos/silverstripe/silverstripe-framework/issues/4442","id":125786296,"user":{"login":"sminnee","id":59968,"avatar_url":"https://avatars.githubusercontent.com/u/59968?v=3","gravatar_id":"","url":"https://api.github.com/users/sminnee","html_url":"https://github.com/sminnee","followers_url":"https://api.github.com/users/sminnee/followers","following_url":"https://api.github.com/users/sminnee/following{/other_user}","gists_url":"https://api.github.com/users/sminnee/gists{/gist_id}","starred_url":"https://api.github.com/users/sminnee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sminnee/subscriptions","organizations_url":"https://api.github.com/users/sminnee/orgs","repos_url":"https://api.github.com/users/sminnee/repos","events_url":"https://api.github.com/users/sminnee/events{/privacy}","received_events_url":"https://api.github.com/users/sminnee/received_events","type":"User","site_admin":false},"created_at":"2015-07-29T00:08:47Z","updated_at":"2015-07-29T00:08:47Z","body":"I can see the benefits of using Lambdas too, but at this stage, I'm less interested in the specific merits of individual DI container and service provider systems, as I am frustrated at the amount of monolithic tight-coupling we have. It shouldn't be the case that SilverStripe comes down from the mountain to decide whether Yaml or Lambdas are better—project developers should have some choice.\r\n\r\nThere are two main areas of interconnection:\r\n\r\n  * *Retrieving service object from the container:* This is what PSR-11 is trying to address; however, we'll see how long it takes to. It's basically an interface defining `->get($id)` and `->has($id)` methods. If we bound to an interface rather than the `Injector` class we could probably let people swap this out, but right now there's no clear 3rd party interface to bind to. In the short term we could just make InjectorInterface and let people build adapters.\r\n\r\n * *Defining services within the container:* Injector does this with configuration sourced from yaml. Other systems do this in other ways. Ideally, we would want to be able to compose a number of service providers into a single DI container. This would let us pull in SilverStripe's default services (configured in the yaml, presumably) and use them alongside. The league's container's `ServiceProvider` would allow this; not sure about other systems.\r\n\r\nOne approach would be to build a `silverstripe-league-container` package that bridged league/container into Injector in these two places.\r\n\r\nOnce PSR-11 comes out I'd like to see us use the interfaces provided by that, and then we can hopefully tie things together without needing adapter packages."}}