Why is ITokenProvider an IEventHandler, and not just an IDependency?

Topics: Core
Jul 25, 2015 at 10:06 PM
Title says it all really.

I was wondering if anyone could shed some light into this? Is there a valid reason it needs to be an IEventHandler, or is this just an oversight?

I changed it locally to IDependency and tokens still appeared to work like normal.
Developer
Jul 26, 2015 at 11:49 PM
One reason I can think of is so that other modules don;t need a project/assembly reference on the tokens module in order to implement a provider. This means that even if the Tokens module wouldn't be present, the module implementing the provider would still compile.
Now in practice, this will probably never be the case and one might just as well add a reference to Orchard.Tokens, but it may be a good pattern to follow anyway as to decrease the tight coupling between modules. the downside of this approach is that you'll typically duplicate the interface declaration in your modules, as is done in Orchard.Media for example. Implementing IEventHandler means you are taking advantage of Orchard's event bus.
Jul 27, 2015 at 10:03 AM
Ah I see.

I did notice that Orchard.Core.Settings.Tokens.SettingsTokens implements its own version of ITokenProvider, and I guessed that this was in order to avoid the dependency on Orchard.Tokens.