Orchard.Tokens

Topics: General
Nov 9, 2011 at 5:41 PM

I am trying to use The ITokenProvider in Orchard to add my own tokens to the Application. There is an example online :

http://weblogs.asp.net/bleroy/archive/2011/07/22/future-orchard-part-1-introducing-tokens.aspx

Now I now how to implement my class using the above example.....

-What if i was using different tokens from different Token Classes implementations?

The _token.Replace(...) they are using in the example do they get it through Orchard Services, is it an instance of every Token Implementation?

I Just Want A Clear Orchard Way of how to use it properly without writing some dirty code..

I would really appreciate if Anybody could give me an Answer?

Thank You very much in advance!!!!!!!

Nov 9, 2011 at 6:14 PM
Edited Nov 9, 2011 at 6:14 PM

That tutorial covers everything ... is there a specific part you don't understand? You need to implement an ITokenProvider to describe your tokens to the system, and then any call to ITokenizer.Replace(...) will pick up your new tokens.

Nov 9, 2011 at 6:55 PM

Thank you so much for your quick anwer

1.So this ITokenizer interface i pick it up through my controller and then the Replace should do the trick..

2. My implementation of ITokenProvider will just be picked up at runtime by the dependency injector and Bam Bam magic happens and all my tokens are in the system?

 

Thank you in advance again!!!!!

Coordinator
Nov 9, 2011 at 7:23 PM

1- Yes
2- Bam bam 

Nov 9, 2011 at 7:34 PM
Edited Nov 9, 2011 at 7:35 PM
alisito wrote:

Thank you so much for your quick anwer

1.So this ITokenizer interface i pick it up through my controller and then the Replace should do the trick..

2. My implementation of ITokenProvider will just be picked up at runtime by the dependency injector and Bam Bam magic happens and all my tokens are in the system?

 

Thank you in advance again!!!!!

Dependencies are injected in constructors, you can do this in a controller, and in any other class which is itself a dependency (so for instance you can pull in other dependencies in the constructor of your ITokenProvider, if you need access to any other services!). The usual form is as follows:

 

public class MyController : Controller {

    private readonly ITokenizer _tokenizer;

    public MyController(
        ITokenizer tokenizer
    ) {
        _tokenizer = tokenizer;
    }

    public ActionResult MyAction(string foo) {
        _tokenizer.Replace(...);
    }

}
Nov 9, 2011 at 8:07 PM

So How do I instantiate an instance of ITokenizer so i can do all that because ITokenProvider does not provide the Replace Method? I am still confused..

Nov 9, 2011 at 8:14 PM

This is the error I get:

 

{"None of the constructors found with policy 'Orchard.Environment.AutofacUtil.DynamicProxy2.ConstructorFinderWrapper' on type 'Whatever.Controllers.MyController' can be invoked with the available services and parameters:\r\nConstructor 'Void .ctor(Orchard.IOrchardServices, Orchard.Tokens.ITokenizer)' parameter resolution failed at parameter 'Orchard.Tokens.ITokenizer tokens'."}

Nov 9, 2011 at 8:32 PM

I am missing something?

Coordinator
Nov 9, 2011 at 8:56 PM

Looks like a feature has not been enabled.

Nov 9, 2011 at 8:57 PM

The Solution Was to Enable the Module!!!!!!

Thanks for your Patience.....