IExtensibilityEventArgs Interface |
Namespace: PDTec.IceNet.Core.Runtime.Extensibility
The IExtensibilityEventArgs type exposes the following members.
This example explains how to define and trigger ice.NET extensibility events. We define a IPackageImportedEvent event triggered by an application function to provide the possibility to implement some additional functionality after the actual import.
First we declare the PackageImportedEventArgs class to represent the event data.
public class PackageImportedEventArgs { public IDatabaseRepository Repository { get; internal set; } public IPackage ImportedPackage { get; internal set; } public StringBuilder EventMessages { get; internal set; } }
Next we declare the event interface itself:
public interface IPackageImportedEvent : IExtensibilityEvent<PackageImportedEventArgs> { }
The following code shows how to trigger the event inside the implementation of an application. Afterwards the application accesses the event implementation data. If no event implementation has been registered, the TriggerEvent method returns null instead of the event arguments instance.
PackageImportedEventArgs pEventArgs = ExtensibilityManager.TriggerEvent<IPackageImportedEvent, PackageImportedEventArgs>(() => new PackageImportedEventArgs { Repository = Repository; ImportedPackage = pPackage; EventMessages = new StringBuilder(); }); if (pEventArgs != null) { Console.WriteLine(pEventArgs.EventMessages.ToString(); }
This example explains how to implement and register ice.NET extensibility events.
The following code shows how to implement an event handler. The EventImpl attribute connects the implementation class to the event interface.
[ExtensibilityEventImpl(Interface=typeof(IPackageImportedEvent))] public class PackageImportedEventImpl : IPackageImportedEvent { public void Execute(PackageImportedEventArgs e) { string packageName = e.Package.Name; if (string.IsNullOrEmpty(e.Package.Description)) { e.Package.Description = "This is a newly imported package."; } e.EventMessages.AppendLine("Imported package [" + e.Package.Name + "]."); } }
The following code shows how to register the event implementation assembly.
<ice.net>
<extensibility>
<implementationAssembly assemblyName="MyCorp.MyApp.BusinessLogic"/>
</extensibility>
</ice.net>