New MG3 Feature: Dynamic viewMappings

Some of the new features in MG3, such as its revised core, focus on work being done in the more "enterprise" arena. A specific case that I'm working hard to support is the case where many customers are running "their own instance" of a common code base and how to support per-customer modification.

Realizing the use case, let's imagine that you host a blog platform. Customers can sign up and immediately have their own blog deployed. Each blog is running the exact same code base, all hosted on the same server/cluster.

Inevitably, a customer will offer to pony up cash to have a view things change. On the service / controller side, MG3 has you covered by allowing ColdSpring-based definition of services and controllers, allowing you to use ColdSpring "overriding" to one-off services and controllers.

For views, however, things were tricky. To support this case, the concept of "dynamic viewMappings" is implemented.

Model-Glue crawls an array of "view mappings" looking for your application's views: it's defined in your app's Coldspring.xml file.

With dynamic viewMappings added, you can manipulate this list at runtime.

Let's solve our blog engine case, pretending that customer "acmeCorp" needs a suite of custom views, overriding the default views only when a custom is defined. All we have to do is update the viewMappings inside a listener function whenever the user is from acmeCorp:

<cfset var customViewMappings = user.getCompany().getCustomViewMapping() />

<cfif len(customViewMappings)>
    <cfset event.setValue("viewMappingAdvice", viewMappings) />    

Et voila.

See for more information

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
© 2021 Joe Rinehart
BlogCFC was created by Raymond Camden. This blog is running version