NServiceBus icon indicating copy to clipboard operation
NServiceBus copied to clipboard

Saga analyzer diagnostic(s) for improperly used generic types

Open DavidBoike opened this issue 3 years ago • 0 comments

Generally, generic message types aren't supported. In the docs for designing messages it states:

Generic message definitions (e.g. MyMessage<T>) are not supported. It is recommended to use dedicated, simple types for each message or to use inheritance to reuse shared message characteristics.

While this is broadly applicable to handlers, there are special cases in sagas with the ConfigureHowToFindSaga method where a saga-specific diagnostic would be warranted, such as this example sourced from https://github.com/Particular/NServiceBus/issues/6399 that does not work:

public class ScheduledNotification<T> : Saga<ScheduledNotificationData> where T : INotificationCommand
{
    protected override void ConfigureHowToFindSaga(SagaPropertyMapper<ScheduledNotificationData> mapper)
    {
        mapper.MapSaga(saga => saga.SourceId)
             .ToMessage<ScheduleCommand<T>>(command => command.Command.Notification.SourceId);
    }
}

In this case a diagnostic should highlight ScheudleCommand<T> and say that generic types cannot be mapped.

Other uses of generic types should be analyzed to see whether they are even workable and diagnostics added for those situations as well.

DavidBoike avatar May 24 '22 15:05 DavidBoike