Git Product home page Git Product logo

Comments (8)

forgie1 avatar forgie1 commented on August 23, 2024

Prior version 3.2.0 this actually worked.
Will it be working again, or shall we solve it different way?

from di.

dg avatar dg commented on August 23, 2024

In this case, the loadDefinitionsFromConfig() method should be used rather than loadConfig(). There was also a problem with expanding parameters, but it's fixed in 3.2-dev

class DIExtension extends CompilerExtension
{

	public function loadConfiguration()
	{
		$config = $this->loadFromFile(__DIR__ . '/di.neon');
		$this->loadDefinitionsFromConfig($config['services']);
	}

}

Before version 3.2.0 it expanded parameters only inside services but not anywhere else, now it is consistent.

from di.

forgie1 avatar forgie1 commented on August 23, 2024

Thank you, this way it is working again.

from di.

forgie1 avatar forgie1 commented on August 23, 2024

What is not working this way is:

config file in the main app

services:
	service.def:
		factory: FQNofService

DI Extension config file loaded via ... $this->loadDefinitionsFromConfig($config['services']);

services:
	service.def:
		setup:
			- register(FQN1())
			- register(FQN2())

result is:

Nette\DI\ServiceCreationException
Service 'service.def': Factory and type are missing in definition of service.

This was also working prior 3.2.0 using

...
	public function loadConfiguration()
	{
		$this->compiler->loadConfig(__DIR__ . '/di.neon');
	}

In 3.2.0 it is not expanding parameters if $this->compiler->loadConfig() is used or above mentioned Exception is thrown if $this->loadDefinitionsFromConfig($config['services']); is used.

What is the proper way, how to load DI Extension's config.neon file, incl. expanding parameters of services and preventing this DI\Exception to be thrown in v3.2.0?

from di.

forgie1 avatar forgie1 commented on August 23, 2024

@dg shall we wait for any update on this issue, or shall we achieve functionality of adding setup: to services from the main App in the DI Extension .neon files another way (our own) -- not using any of Nette methods $this->compiler->loadConfig() || $this->loadDefinitionsFromConfig($config['services']); in the DI Extension?

from di.

dg avatar dg commented on August 23, 2024

Look, I think your use case is very unusual, so it's definitely better if you solve it yourself.

from di.

forgie1 avatar forgie1 commented on August 23, 2024

OK, I tried it, but it looks the problem is broader.
One must choose:

  • to use $this->compiler->loadConfig() ---> parameters will not be expanded
  • or to use $this->loadDefinitionsFromConfig($config['services']); --> named services loaded this way are not recognized at all using @serviceName in any other .neon file

I mean this:

.neon file in DI Extension

services:
	- Plugin\MyService1(%parameterToBeExpanded%)
	myService2:
		factory: Plugin\MyService2

.neon file is loaded via $this->loadDefinitionsFromConfig() in the DIExtension so parameters are expanded.

.neon file in the main app

services:
	someService:
		factory: ServiceFQN
		setup:
			- attach(@myService2)

The result is Nette\DI\ServiceCreationException:
Reference to missing service 'myService2'

So basically all services must be registered in the main App .neon files, not in .neon files of DIExtension package, only then:

  • %parameters% will be expanded
  • @serviceNames will be possible to use in .neon files

It doesn't look flexible to me -- to use DIExtension is quite complicated this way, if only one of services in the .neon file needs its parameter to be expanded and @serviceName is used in other neon file. It is forcing us to move all services to main app .neon files, or to avoid using %parameters% in DIE, or to use other workaround.

from di.

forgie1 avatar forgie1 commented on August 23, 2024

If $this->compiler->loadConfig() would also expand parameters used in services, all the problems mentioned above would be solved and call of $this->loadDefinitionsFromConfig() would not be needed.

from di.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.