egeloen / IvoryGoogleMapBundle

Google Map API v3 integration for your Symfony2 project.
https://github.com/egeloen/ivory-google-map
MIT License
217 stars 152 forks source link

How to inject ivory_google_map.map to a controller as a service #45

Closed mattsnowboard closed 11 years ago

mattsnowboard commented 11 years ago

I've been making my controllers as services and wanted to use the ivory_google_map.map service. But injecting it the normal way through a setter doesn't work because ivory_google_map.map has prototype scope.

ScopeCrossingInjectionException: Scope Crossing Injection detected: The definition "acme_main.controller.signup" references the service "ivory_google_map.map" which belongs to another scope hierarchy. This service might not be available consistently. Generally, it is safer to either move the definition "acme_main.controller.signup" to scope "prototype", or declare "container" as a child scope of "prototype". If you can be sure that the other scope is always active, you can set the reference to strict=false to get rid of this error.

It seems to me like I wouldn't want the Controller to be in the prototype scope. So how should I inject this service? Am I missing something? It sounds like it's a "bad" idea to inject the whole service container if I don't need to (http://symfony.com/doc/current/cookbook/service_container/scopes.html). Ideally I'd just like to inject something like a "map factory" but that doesn't seem to exist.

geoffrey-brier commented 11 years ago

I'm sorry to announce that there is no 'great' solution to your problem. The only solution for us is to directly inject the whole container (BAD PRACTICE). We have planned to 'redo' this part of the bundle (map factory) but as it is something quite sensible it's gonna take some time.

egeloen commented 11 years ago

The issue is now fixed. I let it open still the doc is not fixed.

egeloen commented 11 years ago

The doc has been updated :) (see here)