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 being developed (actually, I just need to commit to SVN!).
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() />
<cfset var viewMappings = "" />
<cfif len(customViewMappings)>
<cfset viewMappings = event.getValue("viewMappings") />
<!--- Insert the custom mappings first, adding a value like "/views/custom/acmeCorp" --->
<cfset arrayInsertAt(viewMappings, 1, customViewMappings) />
<cfset event.setValue("viewMappings", viewMappings) />
</cfif>
Et voila.


There are no comments for this entry.
[Add Comment]