Classes and interfaces

In this section, each class and interface of the concept will be explained in details.

Kipon.Xrm.ITarget

If you have several entities that need to react on the same event, ex. Email, Appointment, Task, or Quote, Order, Invoice, and you can describe a single interface that will be implemented by all the strongly typed entities, the ITarget interface is your friend. This allow you to do a single interface and a single implementation of services, using the interface to perform whatever action you need to perform.

In other words, the Kipon.Xrm.ITarget interface allow you to have a single implementation of service that is listening for the "same" event on several entities.


namespace Kipon.PluginExample.Entities
{
    public interface IDescriptionChanged : Kipon.Xrm.ITarget
    {
        string Description { get; }
    }

    public partial class Quote : IDescriptionChanged { }
    public partial class SalesOrder : IDescriptionChanged { }
    public partial class Invoice : IDescriptionChanged { }
}

Above code is a simple example of such target interface. The interface has a single property Description, and then it is implemented by the Quote, SalesOrder and Invoice entities. Because all these entity classes has a Description property, the actual implementation is already there from the code generated code.


namespace Kipon.PluginExample.Plugins.Sales
{
    public class SalesDescriptionLoggingPlugin : Kipon.Xrm.BasePlugin
    {
        public void OnPostCreate(Entities.IDescriptionChanged target)
        {
            // do some logging or whatever with the description
        }

        public void OnPostUpdate(Entities.IDescriptionChanged target)
        {
            // do some logging or whatever with the description
        }
    }
}

Above plugin will be triggered on create for any entity implementing the IDescriptionChanged, in our case Quote. SalesOrder and Invoice. Be aware that the create method will be called even if Description is unassigned. (there is no default filtering on Create Event.) The OnPostUpdate will be called on any change to the Description field for Quote SalesOrder and Invoice.

If you later need to add more entities, (ex. opportunity for this scenario), just implement the IDescriptionChanged on the Opportunity class, compile, and run the deploy script. That will add a step registration for the opportunity.

© Kipon ApS 2020, 2021, 2022, 2023, 2024. All content on the page is the property of Kipon ApS. Any republish or copy of this content is a violation. The content of this site is NOT open source, and cannot be copied, republished or used in any context without explcit permission from the owner.