If you are new to dI.Hook, please visit the product page for Overview, Release Version and Source Code.
One of the ways to adding hook(s ) in the HookRepository is to define them in Application Configuration file and then loading an appropriate configuration in repository. The other ways are mentioned in How to Add Hooks in a Repository post
Step 1 – Defining configuration
The above configuration has an element repositories that has multiple repository elements.
A repository element has following attributes
- Name: This represents a unique name of the repository. A repository is fetched from configuration using this name.
- Enabled: If the value is ‘false’ then that repository configuration is not considered when loading the configuration. In the above configuration, when repository ‘productionRepositoryDisabled’ is loaded into a HookRepository it will not have any hooks.
Each repository element represents a collection or container of hooks elements. Each hooks element has multiple hook elements.
A hook element has multiple attributes
- Name: Name of the hook
- Type: Fully qualified type of the hook to be added to the repository. This hook should inherit from IHook interface
This relation can be summarized as:
Step 2 – Loading Configuration into Repository
To load configuration of a repository with name ‘default’, the code is fairly simple
To load a specific repository. Say, productionRepository from configuration from a section named ‘dIHookConfiguration’ in the ApplicationConfiguration the code should be
If the ‘enabled’ property of a repository is false, there will be no hooks added in the repository. To verify this, you can try the code below