Why can't I auto-wire NFileTemplate?

about a year ago

petr.pavel
Member | 438
+
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.


Life is what you make it.

Check & Delete: Bookmarklet pro jednoduché mazání dokumentů z My Kindle Library.

about a year ago

petr.pavel
Member | 438
+
0
-

Same is true for NMail.

/**
 * @return NMail
 */
public function createNette__mail()
{
    $service = new NMail;
    $service->setMailer($this->getService('nette.mailer'));
    return $service;
}

Life is what you make it.

Check & Delete: Bookmarklet pro jednoduché mazání dokumentů z My Kindle Library.

about a year ago

Jan Tvrdík
Nette guru | 1989
+
0
-

Because these are factories, not services.


about a year ago

petr.pavel
Member | 438
+
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() )

Life is what you make it.

Check & Delete: Bookmarklet pro jednoduché mazání dokumentů z My Kindle Library.

about a year ago

Jan Tvrdík
Nette guru | 1989
+
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)

about a year ago

petr.pavel
Member | 438
+
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.


Life is what you make it.

Check & Delete: Bookmarklet pro jednoduché mazání dokumentů z My Kindle Library.

Board footer

Nette Tracy Latte Tester Login Register Česká verze