Select version
v7.7 v7.6 v7.5 v7.3 v7.1 v7.0 v6.8 v6.7 v6.6 v6 v5 v4 v3 v2

Add resources through ClientDependency

uCommerce uses ClientDependency to package, versioning, and outputting resources in the backend of uCommerce. It can sometimes be useful to hook into that framework in order to modify styling, hook in new javascript functions or add new services, directives, or controllers to our Angular Application.

Under the hood

We leverage our IoC container to hook up new controls that can deliver different front-end resources for the backend application. In the container we have a single component that hooks up all required resources used out of the box. Each of the items in the array listed below hooks up different things.

  • JavascriptResourcesIncludeList
    • Includes frameworks like JQuery and AngularJS
  • ResourcesIncludeList
    • Includes all default styling among with components for our AngularJS application
  • WidgetResourcesIncludeList
    • Finds all resources for Widgets including AngularJS directives, servies, controllers and more
  • ApplicationBootStrapper
    • Bootstraps the application with AngularJS
    
    
    <component 
    	id="controls.ucommerceMain"
    	service="UCommerce.Presentation.UI.Resources.IResourcesControls, UCommerce.Presentation"
    	type="UCommerce.Presentation.UI.Resources.Impl.ResourcesControls, UCommerce.Presentation" >
    	<parameters>
    		<resouresIncludeLists>
    			<array>
    				<item>${JavascriptResourcesIncludeList}</item>
    				<item>${ResourcesIncludeList}</item>
    				<item>${WidgetResourcesIncludeList}</item>
    				<item>${ApplicationBootStrapper}</item>
    			</array>
    		</resouresIncludeLists>
    	</parameters>
    </component>
    
    

Including your own set of resources

If you want to include your own resources into the backend you need to add a new item into the list shown above. The types included in the list is of type 'UCommerce.Presentation.UI.Resources.IResourcesIncludeList, UCommerce.Presentation'. The method.

Implementing IResourcesIncludeList

The interface is pretty easy implemented as we only need to return a single control, which has the responsibility of delivering the resources for ClientDependency. ClientDependency will look for attriutes on the controls to find the resources needed. Standard implementation looks like the class below. In the implementation we just return itself, which is tagged with the attributes for ClientDependency telling it the resources it needs to load.

    
    
    	[ClientDependency(ClientDependencyType.Javascript, "scripts/App/loader.js", "UCommerce", Priority = 1000)]
    	public class ApplicationBootStrapper : Control, IResourcesIncludeList
    	{
    		public Control GetControl()
    		{
    			return this;
    		}
    	}
    
    

Quick Word on our AngularJS application

Even though uCommerce is still running on ASP.NET webforms we have an angular application running underneath. If you want to build your front-end controls for the backend using Angular you can do that. It will require you to hook in your own control into the resouresIncludeLists in the control above. It needs to be before the ${ApplicationBootStrapper} element as it is not yet possible to lazy load controls into the AngularJS application.

To register a directive you can output the following resource:

    
    
    	function ucommerceWidgets() {
    		return {
    			restrict: 'E',
    			transclude: true,
    			replace: true,
    			scope: {
    				type: '&',
    				header: '=',
    				close: '&',
    				timeout: '@'
    			},
    			templateUrl: UCommerceClientMgr.BaseUCommerceUrl + 'scripts/app/directives/ucommerce-widgets/widgets.html',
    			controller: uc_widgetsController,
    			link: function (tElement, tAttr) {
    
    			}
    		};
    	} 
    
    	angular.module('ucommerce.directives').directive("ucommerceWidgets", ucommerceWidgets);
    
    

To register a controller you can output the following resource:

    
    
    	function uc_widgetsController($scope, uCommerceWidgetService, $timeout) {
    
    	}
    
    	angular.module('ucommerce').controller("widgetsController", uc_widgetsController);
    
    

Registering your control

If you're interested in how to register your new component in our container, please read How to Register a Custom Component

Summary

In this article we covered

  • How uCommerce loads resources into the backend
  • How you can implement 'System.Web.Ui.control' to deliver resources for ClientDependency
  • How you can register your compment and hook it into the 'controls.ucommerceMain' component in our container
uCommerce Aps - Studsgade 29B - 8000 Aarhus C - Denmark
Phone +45 61 799 997 - Email info@ucommerce.dk uCommerce logo