Classes and interfaces

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

Kipon.Xrm.Attributes.TargetAttribute

The [Target] attribute can be used to decorate a parameter for a plugin step, and that way indicate that the parameter should be parsed a target entity.

You only need to use this attribute if you, for whatever reason, do not wish to follow one of the recommended approaches:

  • 1. Create a jummy jummy interface that extends the I[entity]Target interface. This is the most SOLID apprach, because creating and interface is removing the dependency to the underlying entity class implementation, and ensure that all dependencies are based on abstractions.
  • 2. Use the naming convention of the Kipon.Solid framework by naming the parameter "target"

using Kipon.Xrm.Attributes;

namespace Kipon.PluginExample.Plugins.AttributeExamples
{
    public class TargetPlugin : Kipon.Xrm.BasePlugin
    {
        // 1 best pratcise for injecting ... the INameChanged is a jummy jummy interface extending IContactTarget
        public void OnPreCreate(Entities.Account.INameChanged contact) { }

        // 2 less good pratcise, injecting the full account target by naming convention
        public void OnPreCreate(Entities.Account target) { }

        // 3 less good pratcise, injecting the full account target by parameter decorator
        public void OnPreCreate([Target]Entities.Account contact, ServiceAPI.ISomeInterface service) { }
    }
}

Above example is demonstrating the three different ways you can inject the contact target image into plugin steps.

The INameChanged is defined like this:


namespace Kipon.PluginExample.Entities
{
    public partial class Account
        : Account.INameChanged
    {
        public interface INameChanged : IAccountTarget
        {
            string Name { get; set; }
        }
    }
}

The target can only be injected into plugin steps. Parse them to services method if needed there.

© Kipon ApS 2020, 2021, 2022, 2023. 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.