On Thursday, 20 November 2014, Hussein B. <[email protected]> wrote:
> Hi, > > Lets say that you are framework creator and to use your framework, you > defined a macro called defcontroller where the users of your framework add > their logic. > > You -as framework creator- how would you load user defined source code > files and collect their defcontroller definitions? > > Thanks for help. > Frameworks like you describe tend to introduce a lot of complexity and rigidity to the system due to the inversion of control between the application and the framework. This approach is generally frowned upon in this community, as most people feel that Clojure gives you enough options to get the functionality of a framework through libraries (which are called by the application, thus avoiding the inversion). That being said, you have a few options. The most obvious one from the way you ask would be to point you towards load, which reads and compiles a file. However, you then have to figure out which function does what in the compiled namespace, which will require a lot of implicit conventions between client code and your framework. To me, implicit is usually bad when it comes to code. It's nice for 15 minutes blog screencasts, but falls apart as applications grow. A more robust route (in my opinion at least) would be to define a multimethod that the users would extend, and use that as your entry point for the framework. that way you can simply load the file, and multimethod extensions (defmethod) will be loaded into your framework's code. I would still urge you to carefully consider whether what you want to do cannot be done with a more library oriented approach. For example, the way Compojure routes work seem to map nicely to the idea of registering controllers with a web framework, but in a completely "library" style. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
