1111
1212use Geocoder \Laravel \Facades \Geocoder ;
1313use Geocoder \Laravel \ProviderAndDumperAggregator ;
14- use Illuminate \Support \Collection ;
1514use Illuminate \Support \ServiceProvider ;
16- use ReflectionClass ;
1715
1816class GeocoderService extends ServiceProvider
1917{
@@ -27,23 +25,30 @@ public function boot()
2725 "config "
2826 );
2927 $ this ->mergeConfigFrom ($ configPath , "geocoder " );
30- $ this ->app ->singleton ("geocoder " , function () {
31- return (new ProviderAndDumperAggregator )
32- ->registerProvidersFromConfig (collect (config ("geocoder.providers " )));
28+
29+ $ providerAndDumperAggregator = (new ProviderAndDumperAggregator )
30+ ->registerProvidersFromConfig (collect (config ("geocoder.providers " )));
31+
32+ $ this ->app ->singleton ("geocoder " , function ($ app ) use ($ providerAndDumperAggregator ) {
33+ return $ providerAndDumperAggregator ;
3334 });
35+
36+ // Resolve dependency via class name
37+ // i.e app(ProviderAndDumperAggregator::class) or _construct(ProviderAndDumperAggregator $geocoder)
38+ $ this ->app ->instance (ProviderAndDumperAggregator::class, $ providerAndDumperAggregator );
3439 }
3540
3641 public function register ()
3742 {
3843 $ this ->app ->alias ("Geocoder " , Geocoder::class);
3944 }
4045
41- public function provides () : array
46+ public function provides (): array
4247 {
4348 return ["geocoder " ];
4449 }
4550
46- protected function configPath (string $ path = "" ) : string
51+ protected function configPath (string $ path = "" ): string
4752 {
4853 if (function_exists ("config_path " )) {
4954 return config_path ($ path );
0 commit comments