0

Is there a way to create an interface for a module that any host application can be expected to implement?

We've got a couple apps that have a lot of code that is common that we'd like to refactor into modules, but sometimes the module may need to call runEvent or setNextEvent for a handler method that lives in the host application due to unique behavior and implementation.

Can I specify in the module a contract like "host application must implement the following handlers: 'admin.foo', 'admin.bar', ..."?

I am guessing there's a module load intercept I could do this in manually, but I'm wondering if there's a convention so I can just drop the list in somewhere rather than copy-pasting boilerplate code into every module.

jinglesthula
  • 4,446
  • 4
  • 45
  • 79

1 Answers1

0

You can specify dependencies within your ModuleConfig.cfc : this.dependencies = [ "myOtherModule" ]. Those dependencies will load before the module. At this time, there is no way to "interface" a module to conform to a collection of handlers.

Typically, though, passing through to other modules this is easily handled by custom routing within the module configuration, rather than by a new implementation:

addRoute(
    pattern="/this-module/foo",
    moduleRouting="that-module"
)

or

addRoute(
    pattern="/this-module/foo",
    module="that-module",
    handler="oldFoo"
    action="bar"
)

More on routing

JClausen
  • 321
  • 2
  • 2