The IAddin Interface
- Last UpdatedJun 02, 2022
- 2 minute read

What distinguishes an addin from any other .NET assembly is that an addin must contain a class which implements the IAddin interface. When the CAF loads and starts an addin it interrogates the assembly for the class which implements this interface, creates an instance of this class and calls the IAddin.Start method.
The following code is a simple example of a class which implements the IAddin interface.
This is the AttributeBrowserAddin.cs file which is part of the AttributeBrowserAddin sample project which can be found in the samples directory. The Start method performs the initialization of the Addin.
//Copyright 1974 to current year. AVEVA Solutions Limited and its subsidiaries. All rights reserved in original code only.
using System;
using System.Collections.Generic;
using System.Text;
// Add additional using statements
using Aveva.ApplicationFramework;
using Aveva.ApplicationFramework.Presentation;
using Aveva.Core.Presentation;
using Aveva.Core.Database;
namespace Aveva.Core.Samples
{
public class AttributeBrowserAddin : IAddin
{
private DockedWindow attributeListWindow;
private AttributeListControl attributeListControl;
#region IAddin Members
public string Description
{
get
{
return "Provides a simple attribute browser";
}
}
public string Name
{
get
{
return "AttributeBrowserAddin";
}
}
public void Start(ServiceManager serviceManager)
{
// Create Addins Windows
// Get the WindowManager service
IWindowManager windowManager = DependencyResolver.GetImplementationOf<IWindowManager>();
attributeListControl = new AttributeListControl();
// Create a docked window to host an AttributeListControl
attributeListWindow = windowManager.CreateDockedWindow("Aveva.AttributeBrowser.AttributeList", "Attributes", attributeListControl, DockedPosition.Right);
attributeListWindow.Width = 200;
// Docked windows created at addin start should ensure their layout is saved between sessions.
attributeListWindow.SaveLayout = true;
// Create and register addins commands
// Get the CommandManager
ICommandManager commandManager = DependencyResolver.GetImplementationOf<ICommandManager>();
ShowAttributeBrowserCommand showCommand = new ShowAttributeBrowserCommand(attributeListWindow);
commandManager.Commands.Add(showCommand);
// Add event handler for current element changed event.
CurrentElement.CurrentElementChanged += new CurrentElementChangedEventHandler(CurrentElement_CurrentElementChanged);
}
void CurrentElement_CurrentElementChanged(object sender, CurrentElementChangedEventArgs e)
{
// Set the window title to the name of the element.
string windowTitle = "Attributes of element " + CurrentElement.Element.GetAsString(DbAttributeInstance.FLNM);
attributeListWindow.Title = windowTitle;
// Clear attribute list
attributeListControl.Clear();
// Populate the attribute list with attributes of the current element
foreach (DbAttribute attribute in CurrentElement.Element.GetAttributes())
{
try
{
string elAsString = CurrentElement.Element.GetAsString(attribute);
attributeListControl.AddAttribute(attribute.Name, elAsString);
}
catch (Exception exception)
{
//MessageBoxEx.Show(exception.Message + ", "+ attribute.Name);
string excMessage = exception.Message;
}
}
}
public void Stop()
{
}
#endregion
}
}