Dependency Injection Configuration
The DependencyInjection configuration section allows additional components to be registered with a running PowerTSM application without having to touch or rebuild its source code. Each entry points to a .dll file and names a method inside it. On startup, that method is loaded via reflection and called with the application’s dependency injection container, exactly as if it had been called directly in code.
This is primarily useful for compiled products such as the PowerTSM HTTP API, where no access to the entry point (ITsm.Create()) exists. The method referenced here can call any of the same registration methods (UseCustomFlag, UseTimeSeriesDataStore, etc.) that would otherwise be called directly in code.
Configuration Path
Section titled “Configuration Path”HAKOM:DependencyInjectionConfiguration Structure
Section titled “Configuration Structure”DependencyInjection└─ CustomRegistrations └─ CustomRegistration └─ {Name} ├─ Name (must repeat {Name}) ├─ Assembly ├─ RegistrationMethod └─ ClassNameQuick Start
Section titled “Quick Start”<HAKOM> <DependencyInjection> <CustomRegistrations> <CustomRegistration Name="Custom_Data_Store"> <Assembly>MyCompany.CustomDataStore.dll</Assembly> <RegistrationMethod>UseCustomDataStore</RegistrationMethod> <ClassName>MyCompany.CustomDataStore.ContainerExtensions</ClassName> </CustomRegistration> </CustomRegistrations> </DependencyInjection></HAKOM>{ "DependencyInjection": { "CustomRegistrations": { "CustomRegistration": { "Custom_Data_Store": { "Name": "Custom_Data_Store", "Assembly": "MyCompany.CustomDataStore.dll", "RegistrationMethod": "UseCustomDataStore", "ClassName": "MyCompany.CustomDataStore.ContainerExtensions" } } } }}HAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Data_Store__Name=Custom_Data_StoreHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Data_Store__Assembly=MyCompany.CustomDataStore.dllHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Data_Store__RegistrationMethod=UseCustomDataStoreHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Data_Store__ClassName=MyCompany.CustomDataStore.ContainerExtensionsThis is equivalent to calling container.UseCustomDataStore() directly in code, where UseCustomDataStore is a public static IContainer UseCustomDataStore(this IContainer container) method defined on the MyCompany.CustomDataStore.ContainerExtensions class inside MyCompany.CustomDataStore.dll.
Configuration Elements
Section titled “Configuration Elements”Each CustomRegistration entry describes one method call.
Path: HAKOM:DependencyInjection:CustomRegistrations:CustomRegistration:{Name}
| Element | Type | Default | Required | Description |
|---|---|---|---|---|
Name |
string |
— | ✓ | A unique identifier for this registration. Used to distinguish entries from each other and referenced in error messages if something goes wrong. Allowed values: any string, unique among all registrations. Example: Custom_Data_Store. |
Assembly |
string |
— | ✓ | The path to the .dll file containing the registration method. An absolute path is used as-is; a relative path is resolved the same way HAKOM.xml itself is located (see Where Configuration Files Are Located). Allowed values: an absolute or relative path to a .dll file. Example: MyCompany.CustomDataStore.dll. |
ClassName |
string |
— | ✓ | The fully qualified name of a static class in that assembly containing the registration method. Allowed values: a fully qualified class name (namespace and class). Example: MyCompany.CustomDataStore.ContainerExtensions. |
RegistrationMethod |
string |
— | ✓ | The name of a public static method on that class. The method must take a single IContainer parameter and nothing else. Allowed values: a method name, without parentheses or parameters. Example: UseCustomDataStore. |
A CustomRegistration entry that’s missing any of these settings throws an exception on startup rather than being silently skipped.
Dependencies of the Registered Assembly
Section titled “Dependencies of the Registered Assembly”The assembly named in Assembly can reference other assemblies of its own. They do not have to be listed anywhere; they are resolved automatically when the registered assembly first needs them:
-
Assemblies the application already contains (the PowerTSM libraries, .NET itself and every other library the application ships with) are always taken from the application. A registered assembly cannot bring its own version of one of these.
-
Every other dependency is searched for as
{AssemblyName}.dllin the following directories, in this order, including all of their subdirectories:- the directory containing the registered assembly
- the directory of the application
%ProgramW6432%\HAKOMand%ProgramFiles(x86)%\HAKOMon Windows,/etc/hakomand/usr/share/hakomon Linux/macOS
The first directory in which a matching file is found is used. The same applies to the dependencies of those dependencies, so a whole chain of assemblies is resolved without further configuration.
The simplest setup is therefore a dedicated directory that contains the registered assembly together with all of its dependencies.
Errors
Section titled “Errors”Since a misconfigured entry can only be detected once the application tries to load and call it, problems in this section surface as exceptions at startup rather than being reported at configuration-parsing time:
| Code | Exception | Situation |
|---|---|---|
HK08015 |
IncompleteCustomRegistrationException |
A required setting (Name, Assembly, RegistrationMethod or ClassName) is missing from an entry |
HK08016 |
AssemblyNotFoundException |
The .dll file named in Assembly cannot be found |
HK08017 |
RegistrationMethodNotFoundException |
The registration method cannot be found. This is the case if: - the assembly contains no class with the fully qualified name given in ClassName- that class is not a static class- the class has no method named RegistrationMethod- that method is not public static- that method does not take exactly one IContainer parameter |
HK08020 |
FailedToLoadAssemblyException |
The .dll file was found but could not be loaded (e.g. wrong platform, corrupted file) |
Examples
Section titled “Examples”Registering Multiple Components
Section titled “Registering Multiple Components”Multiple CustomRegistration entries can be configured at once, each pointing to a different method call. In XML, each entry is its own <CustomRegistration> element disambiguated by its Name attribute. In JSON and environment variables, which represent configuration as nested key-value pairs rather than XML elements, each registration is keyed directly by its own Name instead. In these two formats, the Name value additionally has to be repeated as its own setting inside each entry, since the key alone is not read as the registration’s name. In XML, the Name attribute already covers this.
<HAKOM> <DependencyInjection> <CustomRegistrations> <CustomRegistration Name="Custom_Data_Store"> <Assembly>MyCompany.CustomDataStore.dll</Assembly> <RegistrationMethod>UseCustomDataStore</RegistrationMethod> <ClassName>MyCompany.CustomDataStore.ContainerExtensions</ClassName> </CustomRegistration> <CustomRegistration Name="Custom_Flags"> <Assembly>MyCompany.CustomFlags.dll</Assembly> <RegistrationMethod>UseMyCustomFlags</RegistrationMethod> <ClassName>MyCompany.CustomFlags.ContainerExtensions</ClassName> </CustomRegistration> </CustomRegistrations> </DependencyInjection></HAKOM>{ "DependencyInjection": { "CustomRegistrations": { "CustomRegistration": { "Custom_Data_Store": { "Name": "Custom_Data_Store", "Assembly": "MyCompany.CustomDataStore.dll", "RegistrationMethod": "UseCustomDataStore", "ClassName": "MyCompany.CustomDataStore.ContainerExtensions" }, "Custom_Flags": { "Name": "Custom_Flags", "Assembly": "MyCompany.CustomFlags.dll", "RegistrationMethod": "UseMyCustomFlags", "ClassName": "MyCompany.CustomFlags.ContainerExtensions" } } } }}HAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Data_Store__Name=Custom_Data_StoreHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Data_Store__Assembly=MyCompany.CustomDataStore.dllHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Data_Store__RegistrationMethod=UseCustomDataStoreHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Data_Store__ClassName=MyCompany.CustomDataStore.ContainerExtensions
HAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Flags__Name=Custom_FlagsHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Flags__Assembly=MyCompany.CustomFlags.dllHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Flags__RegistrationMethod=UseMyCustomFlagsHAKOM__DependencyInjection__CustomRegistrations__CustomRegistration__Custom_Flags__ClassName=MyCompany.CustomFlags.ContainerExtensions