Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a type resolver to be replaced by another implementation later. #1166

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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