Comments (8)
Prior version 3.2.0 this actually worked.
Will it be working again, or shall we solve it different way?
from di.
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.
Thank you, this way it is working again.
from di.
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.
@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.
Look, I think your use case is very unusual, so it's definitely better if you solve it yourself.
from di.
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.
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)
- Multifactory does not work
- Dynamic parameter does not work in static parameter HOT 27
- SearchExtension: compatible with trait Nette\StaticClass HOT 1
- Parent method with static type, has a badly evaluated return type for factory method in container
- Compiler error in process schema after update to 3.1.4 HOT 2
- Circular reference detected for variables HOT 5
- wrong inject of variables after update 3.1.6 > 3.1.7 HOT 3
- "ERROR: Circular reference detected for:" instead of creating Service with array of strings as parameters HOT 5
- Nette\DI\Config\Loader::load($filePath) loads string parameter '@12345' as string '@@12345' HOT 3
- Parameters defined using function notation in neon config not available when calling getParameter HOT 4
- Support `new` in initializers HOT 1
- Some releases were deleted HOT 1
- Calling ReflectionMethod::__construct() with 1 argument is deprecated in PHP 8.4
- Nette DI: suspicious dumping of objects when generating the container HOT 8
- "Object of class DateTimeImmutable could not be converted to string" after update to 3.2.0
- Parameter removed if static method referenced [BC break] HOT 4
- Parameters in includes
- ReflectionException: Method Nette\DI\Container::createServiceFromStaticFactory() does not exist
- Cause error: Error: Cannot access trait constant self::CONTROL_FLASH_MESSAGE directly HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from di.