Why can't I auto-wire NFileTemplate?

1. about a year ago

petr.pavel
Member
Registered: 2011-06-09
Posts: 393

Why can't I auto-wire NFileTemplate?

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.

 

2. about a year ago

petr.pavel
Member
Registered: 2011-06-09
Posts: 393

Re: Why can't I auto-wire NFileTemplate?

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.

 

3. about a year ago

Jan Tvrdík
Nette guru
Registered: 2008-04-13
Location: Prostějov
Posts: 1883

Re: Why can't I auto-wire NFileTemplate?

Because these are factories, not services.


 

4. about a year ago

petr.pavel
Member
Registered: 2011-06-09
Posts: 393

Re: Why can't I auto-wire NFileTemplate?

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.

 

5. about a year ago

Jan Tvrdík
Nette guru
Registered: 2008-04-13
Location: Prostějov
Posts: 1883

Re: Why can't I auto-wire NFileTemplate?

@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)

 

6. about a year ago

petr.pavel
Member
Registered: 2011-06-09
Posts: 393

Re: Why can't I auto-wire NFileTemplate?

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

Switch to desktop