Understanding "dynamic expansion"

In Mendz.Data.Repository(.Async) CRUDS interfaces, one of the method parameters is "dynamic expansion = null". You may be wondering, what it is? What's it for? Or perhaps even asking why? Well, it's really nothing... until you need to use it. And it can be one of the most powerful features of Mendz.Data.Repository(.Async)'s CRUDS interfaces.

The idea of interfaces as contracts make it difficult to design them with future needs in mind. The truth is, interface designers can never guess what the future might throw in as a requirement. At the same time, it is almost impossible to change an interface definition -- for one, changing the interface is 100% a breaking change.

At the very least, the purpose of the "dynamic expansion" parameter is exactly what "expansion" means: to provide a way to expand. In this context, it intends to let developers "expand" the method signature, allowing the developer to pass in more parameter values than the signature has.

The expansion parameter can be any value. It can be of any type. For example, it can be an ExpandoObject instance. Can you imagine the possibilities now?

In a typical MVC application, a View can be more complicated than rendering for just one model. In fact, most developers create a ViewModel, which contains all the models and values needed by a View. The repositories for these kinds of Views may require the CRUDS method to support the model (say, perhaps, as the aggregate root), and the other models and values in the ViewModel. The expansion parameter can readily allow for this.

It may seem tempting to create repositories against a ViewModel. Or, to use the expansion parameter to pass in the ViewModel. However, note that this can bind the repositories to Views, which may not be desired, specially when the repositories can also be shared/used in batch processing programs with no UIs. Following best practices, and keeping repositories focused on (business/domain) models, it is recommended that the expansion parameter is used to pass in only the additional models and values that the CRUDS implementations may need.

The "dynamic expansion" parameter makes the Mendz.Data.Repository(.Async) CRUDS interfaces flexible and readily scalable. It keeps the CRUDS methods simple, but powerful as-is to accommodate complex requirements. Use Mendz.Data to build repositories that are ready for the future. By design, the Mendz.Data.Repository(.Async) CRUDS interfaces can grow as your application requirements grow.

Comments