|
||
The most direct way to register custom providers or helpers is using the CMSModuleLoader partial class, which is included in the App_Code folder of your web project by default (Old_App_Code folder on web application installations).
1. Extend the CMSModuleLoader partial class inside the App_Code folder. You can either create a new code file for this purpose, or extend an existing definition of the class.
[C#]
using CMS.SettingsProvider; |
2. If you have defined your custom providers in external assemblies, add using statements referring to these assemblies.
3. Create a new class inside the CMSModuleLoader that inherits from CMSLoaderAttribute.
[C#]
private class CustomProviderLoader : CMSLoaderAttribute |
4. Add the attribute defined by the internal class before the definition of the CMSModuleLoader partial class.
[C#]
public partial class CMSModuleLoader |
5. Override the Init method inside the attribute class.
[C#]
public override void Init() |
6. In the Init method, assign a new instance of your custom provider class to the ProviderObject property of the original provider (UserInfoProvider in this example).
[C#]
public override void Init() { UserInfoProvider.ProviderObject = new CustomUserInfoProvider(); } |
You can assign classes from both App_Code and other assemblies.
Note: When customizing helpers, assign a new instance of your custom class into the HelperObject property instead.
Overall code example:
[C#]
using CMS.SettingsProvider; |
The application now uses your customized provider(s) instead of the default functionality.