.NET API
Using the PowerTSM .NET API in a project requires two steps:
- Obtaining and configuring the required packages
- Referencing them in the project
See Installing the .NET API in the Operators Guide for a step-by-step guide.
A complete reference of the API is available in the .NET API Reference.
Extending or Overriding PowerTSM Behavior
Section titled “Extending or Overriding PowerTSM Behavior”The .NET API is built around dependency injection: nearly every part of it (storage providers, flags, data types, time zones, …) is a registered component that can be swapped out for a custom implementation. There are two different ways to do this, and the right one depends on whether the entry point of the application is owned.
When the Entry Point Is Owned
Section titled “When the Entry Point Is Owned”If an application that calls ITsm.Create() is written and maintained directly, a custom component is registered directly in code, right where the ITsm instance is created:
Register a custom flag in code
Section titled “ Register a custom flag in code”var tsm = ITsm.Create(container =>{ container.UseCustomFlag(11, 35, "MyCustomFlag");}, true);Concrete walkthroughs of code-based registration can be found here:
When the Entry Point Is Not Owned
Section titled “When the Entry Point Is Not Owned”If a compiled PowerTSM application that already calls ITsm.Create() internally is used instead — for example the PowerTSM HTTP API — no source code is available to add a registration to. In that case, the same registration can be described in HAKOM.xml (or any other configuration source) instead. The application reads that configuration at startup and calls the specified registration method automatically, using reflection:
Register a custom flag through configuration
Section titled “ Register a custom flag through configuration”<DependencyInjection> <CustomRegistrations> <CustomRegistration Name="My_Custom_Flags"> <Assembly>MyCompany.CustomFlags.dll</Assembly> <RegistrationMethod>UseMyCustomFlags</RegistrationMethod> <ClassName>MyCompany.CustomFlags.ContainerExtensions</ClassName> </CustomRegistration> </CustomRegistrations></DependencyInjection>Here, UseMyCustomFlags is just a regular IContainer extension method, written and compiled into its own assembly — it can call UseCustomFlag(...) (or any other registration) exactly like the code sample above.
Registration method in a separate assembly
Section titled “ Registration method in a separate assembly”using HAKOM.DependencyInjection.Core.Net.Api;using HAKOM.TSM.Net.Api.Flags.Extensions;
namespace MyCompany.CustomFlags{ public static class ContainerExtensions { public static IContainer UseMyCustomFlags(this IContainer container) { return container.UseCustomFlag(11, 35, "MyCustomFlag"); } }}Both approaches end up calling the exact same registration methods on the same IContainer — configuration is just a way to trigger that call from the outside when the application’s code cannot (or should not) be touched.