Registering providers using assembly attributes
The most direct way to register custom providers, helpers or managers is using assembly attributes.
Edit your provider class.
Add a using statement for the CMS namespace:
using CMS;
Register your custom providers by adding assembly attributes above the class declaration, for providers, helpers or managers respectively:
- RegisterCustomProvider
- RegisterCustomHelper
- RegisterCustomManager
The parameter of each attribute must contain the exact type of the corresponding custom class (specified as a System.Type object).
You can assign classes from both App_Code and other assemblies. If your custom class is located in an external assembly, you need to perform the following steps to ensure that the RegisterCustom attributes work correctly:
Open the solution in Visual Studio.
Ensure that your project has a reference to the CMS.Core dll (located in the Lib folder of the Kentico project).
Edit your custom assembly’s AssemblyInfo.cs file (in the Properties folder).
Add the AssemblyDiscoverable assembly attribute:
[assembly:CMS.AssemblyDiscoverable]
Save the file and Build the custom project.
The customization automatically targets the provider object that matches the parent of the specified custom class.
// Registers two custom providers, a helper and a manager
[assembly: RegisterCustomProvider(typeof(CustomShippingOptionInfoProvider))]
[assembly: RegisterCustomProvider(typeof(CMS.CustomProviders.CustomForumPostInfoProvider))]
[assembly: RegisterCustomHelper(typeof(CustomCacheHelper))]
[assembly: RegisterCustomManager(typeof(CustomWorkflowManager))]
The system now uses your customized providers instead of the default functionality.
Note: The RegisterCustomProvider attribute cannot be used to register custom e-mail providers (EmailProvider) – you need to follow the web.config registration approach.
See also: Custom E-mail provider example