Skip to content

Commit 5b491b2

Browse files
committed
Change Plugin Step Configs to not use the EventOperation enum but instead use a string to allow for custom messages.
RegisterStep supports both enum and string for ease of use.
1 parent d7255e8 commit 5b491b2

File tree

11 files changed

+88
-40
lines changed

11 files changed

+88
-40
lines changed

XrmPluginCore.Abstractions/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### v1.1.0 - 08 October 2025
2+
* Change Plugin Step Configs to not use the EventOperation enum but instead use a string to allow for custom messages.
3+
14
### v1.0.0 - 01 October 2025
25
* Modifications to CustomAPI definitions to align better with data
36
* Remove Delegate branding after company rebrand to Context&

XrmPluginCore.Abstractions/Enums/EventOperation.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
namespace XrmPluginCore.Enums
22
{
3-
// EventOperation based on CRM 2016
3+
/// <summary>
4+
/// Known system messages based on CRM 2016.<br/>
5+
/// Use this as a basis for plugin step registration.
6+
/// </summary>
47
public enum EventOperation
58
{
69
AddItem,

XrmPluginCore.Abstractions/Interfaces/Plugin/IPluginStepConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface IPluginStepConfig
1616
/// <summary>
1717
/// Event operation that the SDK message processing step is registered for.
1818
/// </summary>
19-
EventOperation EventOperation { get; }
19+
string EventOperation { get; }
2020

2121
/// <summary>
2222
/// Stage in the execution pipeline that the SDK message processing step is in.

XrmPluginCore.Tests/Integration/PluginIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void PluginRegistrations_ShouldContainCorrectConfiguration()
9696
registrations.Should().HaveCount(1);
9797
var registration = registrations.First();
9898
registration.EntityLogicalName.Should().Be("account");
99-
registration.EventOperation.Should().Be(EventOperation.Update);
99+
registration.EventOperation.Should().Be(nameof(EventOperation.Update));
100100
registration.ExecutionStage.Should().Be(ExecutionStage.PreOperation);
101101
}
102102
}

XrmPluginCore.Tests/PluginTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System;
99
using System.Linq;
1010
using System.ServiceModel;
11-
using XrmPluginCore;
1211
using XrmPluginCore.Tests.TestPlugins.Bedrock;
1312
using Xunit;
1413
using XrmPluginCore.Extensions;
@@ -157,8 +156,8 @@ public void Execute_CustomMessage_ShouldExecuteAction()
157156
var mockProvider = new MockServiceProvider();
158157

159158
// Setup context for custom message
160-
mockProvider.SetupPrimaryEntityName("custom_message");
161-
mockProvider.SetupMessageName("Execute");
159+
mockProvider.SetupPrimaryEntityName("account");
160+
mockProvider.SetupMessageName("custom_message");
162161
mockProvider.SetupStage(20);
163162

164163
// Act
@@ -249,8 +248,8 @@ public void GetRegistrations_ShouldReturnCorrectRegistrations()
249248

250249
// Assert
251250
registrations.Should().HaveCount(2);
252-
registrations.Should().Contain(r => r.EventOperation == EventOperation.Create);
253-
registrations.Should().Contain(r => r.EventOperation == EventOperation.Update);
251+
registrations.Should().Contain(r => r.EventOperation.Equals(nameof(EventOperation.Create)));
252+
registrations.Should().Contain(r => r.EventOperation.Equals(nameof(EventOperation.Update)));
254253
}
255254

256255
[Fact]

XrmPluginCore.Tests/TestPlugins/TestPlugins.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class TestCustomMessagePlugin : Plugin
3636

3737
public TestCustomMessagePlugin()
3838
{
39-
RegisterPluginStep("custom_message", EventOperation.Execute, ExecutionStage.PreOperation, Execute);
39+
RegisterPluginStep<Entity>("custom_message", ExecutionStage.PreOperation, Execute);
4040
}
4141

4242
private void Execute(LocalPluginContext context)

XrmPluginCore/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### v1.1.0 - 8 October 2025
2+
* Breaking: Change Plugin Step Configs to not use the EventOperation enum but instead use a string to allow for custom messages. RegisterStep supports both enum and string for ease of use.
3+
* Fix: Remove the MessageEntity type since it isn't needed and muddies the waters
4+
15
### v1.0.1 - 2 October 2025
26
* Refactor: Merge CustomAPI into Plugin base class for simplicity
37

XrmPluginCore/Plugin.cs

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,32 @@ public ICustomApiConfig GetRegistration()
125125
/// <param name="executionStage">The execution stage of the plugin registration</param>
126126
/// <param name="action">The action to execute</param>
127127
/// <returns>The <see cref="PluginStepConfigBuilder{T}"/> to register filters and images</returns>
128+
[Obsolete("Use RegisterStep instead")]
128129
protected PluginStepConfigBuilder<T> RegisterPluginStep<T>(
129130
EventOperation eventOperation, ExecutionStage executionStage, Action<LocalPluginContext> action)
130131
where T : Entity
132+
{
133+
return RegisterStep<T>(eventOperation.ToString(), executionStage, sp => action(new LocalPluginContext(sp)));
134+
}
135+
136+
/// <summary>
137+
/// Register a plugin step for the given entity type, event operation, and execution stage with the given action.<br/>
138+
/// The action will get passed a <see cref="LocalPluginContext"/>.<br/>
139+
/// <br/>
140+
/// <b>
141+
/// NOTE: It is strongly adviced to use the <see cref="RegisterPluginStep{T}(EventOperation, ExecutionStage, Action{LocalPluginContext})"/> method instead if possible.<br/>
142+
/// Only use this method if you are registering for a non-standard message.
143+
/// </b>
144+
/// </summary>
145+
/// <typeparam name="T">The entity type to register the plugin for</typeparam>
146+
/// <param name="eventOperation">The event operation to register the plugin for</param>
147+
/// <param name="executionStage">The execution stage of the plugin registration</param>
148+
/// <param name="action">The action to execute</param>
149+
/// <returns>The <see cref="PluginStepConfigBuilder{T}"/> to register filters and images</returns>
150+
[Obsolete("Use RegisterStep instead")]
151+
protected PluginStepConfigBuilder<T> RegisterPluginStep<T>(
152+
string eventOperation, ExecutionStage executionStage, Action<LocalPluginContext> action)
153+
where T : Entity
131154
{
132155
return RegisterStep<T>(eventOperation, executionStage, sp => action(new LocalPluginContext(sp)));
133156
}
@@ -145,6 +168,28 @@ protected PluginStepConfigBuilder<T> RegisterPluginStep<T>(
145168
protected PluginStepConfigBuilder<TEntity> RegisterStep<TEntity, TService>(
146169
EventOperation eventOperation, ExecutionStage executionStage, Action<TService> action)
147170
where TEntity : Entity
171+
{
172+
return RegisterStep<TEntity>(eventOperation.ToString(), executionStage, sp => action(sp.GetRequiredService<TService>()));
173+
}
174+
175+
/// <summary>
176+
/// Register a plugin step for the given entity type, event operation, and execution stage with the given action.<br/>
177+
/// The action will get passed an instance of <typeparamref name="TService"/>.
178+
/// <br/>
179+
/// <b>
180+
/// NOTE: It is strongly adviced to use the <see cref="RegisterStep{TEntity, TService}(EventOperation, ExecutionStage, Action{TService})"/> method instead if possible.<br/>
181+
/// Only use this method if you are registering for a non-standard message.
182+
/// </b>
183+
/// </summary>
184+
/// <typeparam name="TEntity">The entity type to register the plugin for</typeparam>
185+
/// <typeparam name="TService">The service type to pass to the action</typeparam>
186+
/// <param name="eventOperation">The event operation to register the plugin for</param>
187+
/// <param name="executionStage">The execution stage of the plugin registration</param>
188+
/// <param name="action">The action to execute</param>
189+
/// <returns>The <see cref="PluginStepConfigBuilder{T}"/> to register filters and images</returns>
190+
protected PluginStepConfigBuilder<TEntity> RegisterStep<TEntity, TService>(
191+
string eventOperation, ExecutionStage executionStage, Action<TService> action)
192+
where TEntity : Entity
148193
{
149194
return RegisterStep<TEntity>(eventOperation, executionStage, sp => action(sp.GetRequiredService<TService>()));
150195
}
@@ -161,6 +206,27 @@ protected PluginStepConfigBuilder<TEntity> RegisterStep<TEntity, TService>(
161206
protected PluginStepConfigBuilder<T> RegisterStep<T>(
162207
EventOperation eventOperation, ExecutionStage executionStage, Action<IExtendedServiceProvider> action)
163208
where T : Entity
209+
{
210+
return RegisterStep<T>(eventOperation.ToString(), executionStage, action);
211+
}
212+
213+
/// <summary>
214+
/// Register a plugin step for the given entity type, event operation, and execution stage with the given action.<br/>
215+
/// The action will get passed a <see cref="IServiceProvider"/>.
216+
/// <br/>
217+
/// <b>
218+
/// NOTE: It is strongly adviced to use the <see cref="RegisterStep{T}(EventOperation, ExecutionStage, Action{IExtendedServiceProvider})"/> method instead if possible.<br/>
219+
/// Only use this method if you are registering for a non-standard message.
220+
/// </b>
221+
/// </summary>
222+
/// <typeparam name="T">The entity type to register the plugin for</typeparam>
223+
/// <param name="eventOperation">The event operation to register the plugin for</param>
224+
/// <param name="executionStage">The execution stage of the plugin registration</param>
225+
/// <param name="action">The action to execute</param>
226+
/// <returns>The <see cref="PluginStepConfigBuilder{T}"/> to register filters and images</returns>
227+
protected PluginStepConfigBuilder<T> RegisterStep<T>(
228+
string eventOperation, ExecutionStage executionStage, Action<IExtendedServiceProvider> action)
229+
where T : Entity
164230
{
165231
var builder = new PluginStepConfigBuilder<T>(eventOperation, executionStage);
166232
RegisteredPluginSteps.Add(new PluginStepRegistration(builder, action));
@@ -211,21 +277,6 @@ protected CustomApiConfigBuilder RegisterAPI(string name, Action<IExtendedServic
211277
return configBuilder;
212278
}
213279

214-
// TODO: THESE TWO ARE WRONG - IT'S NOT THE ENTITY THAT'S CUSTOM, IT'S THE EVENTOPERATION
215-
protected PluginStepConfigBuilder<MessageEntity> RegisterPluginStep(
216-
string pluginMessage, EventOperation eventOperation, ExecutionStage executionStage, Action<LocalPluginContext> action)
217-
{
218-
return RegisterStep(pluginMessage, eventOperation, executionStage, sp => action(new LocalPluginContext(sp)));
219-
}
220-
221-
protected PluginStepConfigBuilder<MessageEntity> RegisterStep(
222-
string pluginMessage, EventOperation eventOperation, ExecutionStage executionStage, Action<IExtendedServiceProvider> action)
223-
{
224-
var builder = new PluginStepConfigBuilder<MessageEntity>(pluginMessage, eventOperation, executionStage);
225-
RegisteredPluginSteps.Add(new PluginStepRegistration(builder, action));
226-
return builder;
227-
}
228-
229280
private Action<IExtendedServiceProvider> GetAction(IPluginExecutionContext context)
230281
{
231282
// Iterate over all of the expected registered events to ensure that the plugin

XrmPluginCore/Plugins/MessageEntity.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

XrmPluginCore/Plugins/PluginStepConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class PluginStepConfig : IPluginStepConfig
1414

1515
public string Name { get; internal set; }
1616

17-
public EventOperation EventOperation { get; internal set; }
17+
public string EventOperation { get; internal set; }
1818

1919
public ExecutionStage ExecutionStage { get; internal set; }
2020

0 commit comments

Comments
 (0)