Introduction

 RazorBridge provides extensions over default MVC functionality.  The configuration oriented model provides lots of benefit to organize and render view for multiple devices and platforms. 

Need of Extensibility

MVC is nothing but the convention over configuration. It provides default patterns to simplifying the request/response, data transfer from controller to view, template rendering, model binding and many more. Below is some of the example of default MVC pattern to find views in the virtual file location.

Default View location Format

  “~/Views/{ControllerFolder}/ {ActionName}.cshtml”

          ViewLocationFormats = new[]

            {

                "~/Views/{1}/{0}.cshtml",

                "~/Views/{1}/{0}.vbhtml",

                "~/Views/Shared/{0}.cshtml",

                "~/Views/Shared/{0}.vbhtml"

            };

Default Partial View Location Format

            PartialViewLocationFormats = new[]

            {

                "~/Views/{1}/{0}.cshtml",

                "~/Views/{1}/{0}.vbhtml",

                "~/Views/Shared/{0}.cshtml",

                "~/Views/Shared/{0}.vbhtml"

            };

Default File extension supported

            FileExtensions = new[]

            {

                "cshtml",   {Razor file extension}

                "vbhtml", {Web Form file extension}

            };

 We can explicitly call a different view name but it should be in the folder which contains the name of controller or must be in shared folder.

                                         All the features described above have generic nature and for line of business application, there may be need of customization. Suppose we have an application which contains hundreds of pages, than it will be very difficult to manage it inside shared folder.  ASP .net MVC provides a scope to modify and extend the default behavior of existing functionality. RazorBridge enables the way to extend those functionalities.

Anatomy of Plug-in based Architecture 

In web partitioning the application in separate reusable modules and calling it through host application is called plug-in oriented architecture. Partitioning application to separate project helps developers to organize files, tracking bugs, managing structure and naming conventions.

Views can be served to the client on the basis of requested culture and different devices or platform.Files served to client either from Host application as virtual file detection or from plug-ins as embedded resources.

     Configuration file contains a formatted structure in xml, to resolve, find the virtual file path and embedded resources from referenced dll. 

Working model of RazorBridge 

At Present RazorBridge only supports Razor Views. It registers a custom RazorViewEngine (CompositeViewEngine) to application and register custom virtual path provider to Hosting environment. CompositeViewEngine register the file extensions and view location formats respected to C# to limit the search locations for Views and partial views. CompositeViewEngine returns views and partial views with the help of plug-in key and view/partial view key, detecting requested device / platform and throw an error if unable to find the views or partial views. CompositeViewEngine applies early return while search for location (applying default DeviceType or if single DeviceType exists it just pick that one and make that as a default). 

                    RazorBridge provides a base class MVCControllerBase inherited from Controller class which overloads some of the existing functions to support configuration file. All controllers should inherit MVCControllerBase to retrieve view/partial view. Below is the default Action result method and their extension.

Default one:

 

return PartialView();

Or

 return PartialView(“viewName”)

Or

Return PartialView(“viewName”, object model)

Extended One:

return PartialView("pluginName", "viewName");

return PartialView("pluginName", "viewName", object model);

 

RazorBridge contains some Extension methods associated with the @Html helper to render partial views inside the razor syntax.

 

Default One:

@Html.Partial( "PartialViewName")

Or

@Html.Partial("PartialViewName", Model)

 

Extended One:

@Html.Partial( “PluginName”,"PartialViewName")

Or

@Html.Partial(“”PluginName,"PartialViewName", Model)

Scope of Enhancements

 

i)                    As it is in observation for the time being, all suggestions are open and code can be modified according to that.

ii)                  There is no support of rendering views against culture code.

iii)                Code is not written yet to support different platform type.

iv)                Code to discover Layout view and _viewStart is not ready from separate assembly; these files should be within Host Project.

v)                  Fallback is supported if setting is missing from configuration file, as of today not all views are separated in separate project. It needs to be removed once all configuration setting will be available.

vi)                Customization of error message and improvement in error handling in RazorBridge.

 

 

Last edited Jul 17, 2012 at 1:44 PM by kgaurav1023, version 1

Comments

No comments yet.