Command and event execution control
ExtensionPoints prevents multiple events from occurring when APIs are operated during command or event execution. This prevents events from being fired and processed in unexpected situations during command processing, leading to performance degradation and functional bugs. In standard extension development that does not use the ExtensionPoints library, even if you edit the model with the API, the model edit event will fire.
For example, assume the following case. Suppose you have developed a function that creates models in bulk.
public class AddUseCasesCommand : CommandHandlerBase
{
protected override void OnExecute(ICommandContext c, ICommandParams p)
{
for (var i=0;i<10;i++)
{
var useCaseModel = CurrentModel.AddNewModel("UseCases", "UseCase");
//set the fields
useCaseModel.SetField("Name", $"MyUseCase {i}");
useCaseModel.SetField("Description", "MyUseCase");
useCaseModel.SetField("SomeField", "xxx");
}
}
}
In addition, suppose that you have registered an event handler when editing the model field in order to implement some kind of data correction when the user edits the model. There are cases where you don't want the model change event to be handled when the model is created.
public class UseCaseModelFieldChangedEvent : ModelsFieldChangedEventHandlerBase
{
protected override void OnHandle(IEventContext c, ModelFieldChangedEventParams p)
{
//...
}
}
In this case, ExtensionPoints prevents new events from firing even if the model is changed in the OnExecute
method of the command and the OnHandle
method of the event. If you want to perform common initialization for commands and events, please devise such as defining a dedicated class and concentrating the behavior there. It's also a good approach to define your model's behaviors and attributes as classes, for example:
public class UseCaseModel
{
private IModel m_Model;
public UseCaseModel(IModel m)
{
m_Model = m;
}
public void Initialize(int i=0)
{
m_Model.SetField("Name", $"MyUseCase {i}");
m_Model.SetField("Description", "MyUseCase");
m_Model.SetField("SomeField", "xxx");
}
public void SomeMethod()
{
m_Model.SetField(...);
}
}
public class AddUseCasesCommand : CommandHandlerBase
{
protected override void OnExecute(ICommandContext c, ICommandParams p)
{
for (var i=0;i<10;i++)
{
var m = CurrentModel.AddNewModel("UseCases", "UseCase");
var useCaseModel = new UseCaseModel(m);
//set the fields
useCaseModel.Initialize(i);
}
}
}
Note that this suppression mechanism only works within the same extension. Note that we do not suppress events across extensions.