Why can't I auto-wire NFileTemplate?

Notice: This thread is very old.
petr.pavel
Member | 533
+
0
-

Hey guys,
could someone please explain to me why I can't use auto-wiring with NFileTemplate in my mailing class? Thanks.

public function __construct(...parameters that work..., NFileTemplate $latteTemplate) {

My compiled Configurator contains this standard piece of code:

/tmp/cache/_Nette.Configurator/_-c675b5eabb49d33a61eeecfb998ae5f2.php
	/**
	 * @return NFileTemplate
	 */
	public function createNette__template()
	{
		$service = new NFileTemplate;
		$service->registerFilter($this->createNette__latte());
		$service->registerHelperLoader('NTemplateHelpers::loader');
		return $service;
	}

So why can't auto-wiring find it? I'm getting

Service 'emailTemplateModel': No service of type NFileTemplate found. Make sure the type hint in Method EmailTemplateModel::__construct() is written correctly and service of this type is registered.

Nette Framework 2.0.8 (revision b7f6732 released on 2013–01–01), version with prefixes.

petr.pavel
Member | 533
+
0
-

Same is true for NMail.

	/**
	 * @return NMail
	 */
	public function createNette__mail()
	{
		$service = new NMail;
		$service->setMailer($this->getService('nette.mailer'));
		return $service;
	}
Jan Tvrdík
Nette guru | 2595
+
0
-

Because these are factories, not services.

petr.pavel
Member | 533
+
0
-

I see… right…

So is there anything that I can put into my config.neon to call these factories and use their product as a parameter for my model?
The following doesn't work, I assume it's because SystemContainer doesn't exist yet at the time Nette is compiling config.neon into SystemContainer class.

	services:
		emailTemplateModel: EmailTemplateModel(..., SystemContainer::createNette__template())

Same with:

	services:
		emailTemplateModel:
			class: EmailTemplateModel
			setup:
				- setLatteTemplate( SystemContainer::createNette__template() )
Jan Tvrdík
Nette guru | 2595
+
0
-

@petr.pavel: The idea behind factories is to pass to your service (emailTemplateModel) the entire factory, not only one product of the factory (template in this case). Try to use

services:
    emailTemplateModel: EmailTemplateModel(..., @nette.templateFactory)
petr.pavel
Member | 533
+
0
-

Oh my! This is so sweet! Your approach makes a much better sense.

Thank you for taking the time to explain this to me. I still feel like I'm only beginning with Nette.