Skip to content

Commit

Permalink
Merge pull request #1166 from rapmue/type-resolving
Browse files Browse the repository at this point in the history
added a type resolver to be replaced by another implementation later.
  • Loading branch information
danielgerlag committed Sep 10, 2024
2 parents 951ec7c + fcbb47a commit 4a0f4ea
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/WorkflowCore.DSL/Interface/ITypeResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Linq;

namespace WorkflowCore.Interface
{
public interface ITypeResolver
{
Type FindType(string name);
}
}
1 change: 1 addition & 0 deletions src/WorkflowCore.DSL/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddWorkflowDSL(this IServiceCollection services)
{
services.AddTransient<ITypeResolver, TypeResolver>();
services.AddTransient<IDefinitionLoader, DefinitionLoader>();
return services;
}
Expand Down
15 changes: 9 additions & 6 deletions src/WorkflowCore.DSL/Services/DefinitionLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ namespace WorkflowCore.Services.DefinitionStorage
public class DefinitionLoader : IDefinitionLoader
{
private readonly IWorkflowRegistry _registry;
private readonly ITypeResolver _typeResolver;

public DefinitionLoader(IWorkflowRegistry registry)
public DefinitionLoader(IWorkflowRegistry registry, ITypeResolver typeResolver)
{
_registry = registry;
_typeResolver = typeResolver;
}

public WorkflowDefinition LoadDefinition(string source, Func<string, DefinitionSourceV1> deserializer)
Expand Down Expand Up @@ -220,10 +222,11 @@ private void AttachOutputs(StepSourceV1 source, Type dataType, Type stepType, Wo
var dataParameter = Expression.Parameter(dataType, "data");


if(output.Key.Contains(".") || output.Key.Contains("["))
if (output.Key.Contains(".") || output.Key.Contains("["))
{
AttachNestedOutput(output, step, source, sourceExpr, dataParameter);
}else
}
else
{
AttachDirectlyOutput(output, step, dataType, sourceExpr, dataParameter);
}
Expand Down Expand Up @@ -259,11 +262,11 @@ private void AttachDirectlyOutput(KeyValuePair<string, string> output, WorkflowS

}

private void AttachNestedOutput( KeyValuePair<string, string> output, WorkflowStep step, StepSourceV1 source, LambdaExpression sourceExpr, ParameterExpression dataParameter)
private void AttachNestedOutput(KeyValuePair<string, string> output, WorkflowStep step, StepSourceV1 source, LambdaExpression sourceExpr, ParameterExpression dataParameter)
{
PropertyInfo propertyInfo = null;
String[] paths = output.Key.Split('.');

Expression targetProperty = dataParameter;

bool hasAddOutput = false;
Expand Down Expand Up @@ -352,7 +355,7 @@ private void AttachOutcomes(StepSourceV1 source, Type dataType, WorkflowStep ste

private Type FindType(string name)
{
return Type.GetType(name, true, true);
return _typeResolver.FindType(name);
}

private static Action<IStepBody, object, IStepExecutionContext> BuildScalarInputAction(KeyValuePair<string, object> input, ParameterExpression dataParameter, ParameterExpression contextParameter, ParameterExpression environmentVarsParameter, PropertyInfo stepProperty)
Expand Down
15 changes: 15 additions & 0 deletions src/WorkflowCore.DSL/Services/TypeResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using WorkflowCore.Interface;

namespace WorkflowCore.Services.DefinitionStorage
{
public class TypeResolver : ITypeResolver
{
public Type FindType(string name)
{
return Type.GetType(name, true, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DefinitionLoaderTests
public DefinitionLoaderTests()
{
_registry = A.Fake<IWorkflowRegistry>();
_subject = new DefinitionLoader(_registry);
_subject = new DefinitionLoader(_registry, new TypeResolver());
}

[Fact(DisplayName = "Should register workflow")]
Expand Down

0 comments on commit 4a0f4ea

Please sign in to comment.