locked
Directive Processor Parameter Injection RRS feed

  • Question

  • Hi,

    I am creating a custom directive processor and a custom texttemplatingenginehost. My directive processor needs a parameter that I would like to inject with a Unity Container. I have no control about directive processor objects creation so I cannot find the way to do that. The only link between enginehost and directive processor is ResolveDirectiveProcessor, but it returns a Type and not an object.

    Would it be possible to override any method to control DirectiveProcessor objects construction? Or would it be possible to use Unity container to create that kind of objects?

    Thanks in advance!

     

     


    Ruben J. Marrufo
    Tuesday, March 29, 2011 2:26 PM

Answers

  • Hello,

    The construction of a new DirectiveProcessor (“DP”) instance is done by the core text templating engine. There isn’t any way to override the actual construction although it is possible to configure the DP afterwards. The sequence of calls is as follows:

    • The engine asks the host to resolve the DP name (i.e. turn the directive name into a Type)
    • The engine creates an instance of the Type.
    • The engine calls IDirectiveProcessor.Initialize(host) on the new DP, passing in a reference to the host.

    It should be possible to e.g. access a Unity container supplied by the host at this point.

    Since you are adding host-specific behaviour, DP should also implement IRecognizeHostSpecific appropriately.

    (Thanks Duncan Pocklington for the above info).


    --Trevor H.
    Send files to Hotmail.com: "MS_TREVORH"
    Thursday, April 28, 2011 8:27 PM

All replies

  • Hello Ruben,

     

    Thank you for your question.

     

    I am currently looking into this issue and will give you an update as soon as possible.

     

    Thank you for your understanding and support.

     

    Best Regards,

    Ziwei Chen

     

     

     

     

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 1, 2011 9:52 AM
  • Hello,

    The construction of a new DirectiveProcessor (“DP”) instance is done by the core text templating engine. There isn’t any way to override the actual construction although it is possible to configure the DP afterwards. The sequence of calls is as follows:

    • The engine asks the host to resolve the DP name (i.e. turn the directive name into a Type)
    • The engine creates an instance of the Type.
    • The engine calls IDirectiveProcessor.Initialize(host) on the new DP, passing in a reference to the host.

    It should be possible to e.g. access a Unity container supplied by the host at this point.

    Since you are adding host-specific behaviour, DP should also implement IRecognizeHostSpecific appropriately.

    (Thanks Duncan Pocklington for the above info).


    --Trevor H.
    Send files to Hotmail.com: "MS_TREVORH"
    Thursday, April 28, 2011 8:27 PM