Skip to content

Commit

Permalink
Fix null prefix (#151)
Browse files Browse the repository at this point in the history
* Handle null prefixes properly

* Fix null prefix
  • Loading branch information
boma96 authored Sep 22, 2023
1 parent 9769e4d commit 579aa13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/ConductorSharp.Definitions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
pipelines.AddRequestResponseLogging();
pipelines.AddValidation();
})
.AddCSharpLambdaTasks(typeof(ITaskRequestHandler<,>).Assembly.GetName().Name);
.AddCSharpLambdaTasks();

builder.RegisterModule<ConductorModule>();
}
Expand Down
11 changes: 7 additions & 4 deletions src/ConductorSharp.Patterns/Builders/CSharpLambdaTaskBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ Func<TInput, TOutput> lambda
where TWorkflow : ITypedWorkflow
where TInput : IRequest<TOutput>
{
var lambdaTaskNamePrefix = (string)
builder.ConfigurationProperties.FirstOrDefault(prop => prop.Key == CSharpLambdaTask.LambdaTaskNameConfigurationProperty).Value;
var prefixConfigProperty = builder.ConfigurationProperties.FirstOrDefault(
prop => prop.Key == CSharpLambdaTask.LambdaTaskNameConfigurationProperty
);

if (lambdaTaskNamePrefix == null)
if (prefixConfigProperty == null)
throw new LambdaTasksNotEnabledException();

var lambdaTaskNamePrefix = TaskNameBuilder.MakeTaskNamePrefix(prefixConfigProperty.Value as string);

var taskBuilder = new CSharpLambdaTaskBuilder<TInput, TOutput>(
task.Body,
input.Body,
Expand Down Expand Up @@ -73,7 +76,7 @@ public override WorkflowDefinition.Task[] Build()
{
new WorkflowDefinition.Task
{
Name = $"{_lambdaTaskNamePrefix}.{CSharpLambdaTask.TaskName}",
Name = $"{_lambdaTaskNamePrefix}{CSharpLambdaTask.TaskName}",
TaskReferenceName = _taskRefferenceName,
InputParameters = new JObject
{
Expand Down
4 changes: 3 additions & 1 deletion src/ConductorSharp.Patterns/Builders/TaskNameBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public override string Build(Type taskType) =>
private string GetLambdaTaskPrefix()
{
var prefix = (string)_configurationProperties.First(prop => prop.Key == CSharpLambdaTask.LambdaTaskNameConfigurationProperty).Value;
return prefix == null ? string.Empty : $"{prefix}.";
return MakeTaskNamePrefix(prefix);
}

public static string MakeTaskNamePrefix(string prefix) => prefix == null ? string.Empty : $"{prefix}.";
}
}

0 comments on commit 579aa13

Please sign in to comment.