question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example of IActivityTypeProvider based on a single type

See original GitHub issue

Hi,

I’ve a situation where I have a swagger.json file and I want to create an activity for each API call inside swagger file. I created a based activity that accept paramters and is able to do the call.

I’ve created a class that implements IActivityTypeProvider and if I return only one class everything seems to work fine, but when I return a second ActivityDefinition based on the same underling class, I got error because elsa is trying to register multiple time the same activity.

I’ve tried to make the class generic to have a single runtime type for each activity but then I have error like following one and the workflow does not works.

Is there an example that shows how to use a base class to dynamically generates multiple activity definition at runtime? Is this even a supported scenario?

Thanks for any information you can give me.

at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
2022-07-27 13:12:22 [ERR] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware | An unhandled exception has occurred while executing the request.
Elsa.Exceptions.WorkflowException: The activity type 'Activity' has not been registered. Did you forget to register it with ElsaOptions?
   at Elsa.Services.Workflows.ActivityTypeService.GetActivityTypeAsync(String type, CancellationToken cancellationToken)
   at Elsa.Scripting.JavaScript.Handlers.RenderJavaScriptTypeDefinitions.<>c__DisplayClass3_0.<<Handle>b__5>d.MoveNext()
--- End of stack trace from previous location ---
   at Elsa.Scripting.JavaScript.Handlers.RenderJavaScriptTypeDefinitions.Handle(RenderingTypeScriptDefinitions notification, CancellationToken cancellationToken)
   at MediatR.Mediator.PublishCore(IEnumerable`1 allHandlers, INotification notification, CancellationToken cancellationToken)
   at Elsa.Scripting.JavaScript.Providers.DotNetTypeScriptDefinitionProvider.GenerateTypeScriptDefinitionsAsync(StringBuilder builder, ICollection`1 declaredTypes, WorkflowDefinition workflowDefinition, IntellisenseContext context, CancellationToken cancellationToken)
   at Elsa.Scripting.JavaScript.Services.TypeScriptDefinitionService.GenerateTypeScriptDefinitionsAsync(WorkflowDefinition workflowDefinition, IntellisenseContext context, CancellationToken cancellationToken)
   at Elsa.Server.Api.Endpoints.Scripting.JavaScript.TypeDefinitions.Get.Handle(String workflowDefinitionId, IntellisenseContext context, Nullable`1 version, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
alkampfergitcommented, Jul 27, 2022

Found My error, in activity activation I used this piece of code I’ve found on some issue

var activity = (DynamicSendJarvisHttpRequest)ActivatorUtilities.GetServiceOrCreateInstance(context.ServiceProvider, responseType);

And this generates all sort of problem, I’ve changed as for your example to

 var activity = await _activityActivator.ActivateActivityAsync<BaseDynamicSendJarvisHttpRequest>(context);

And everything works as a charm.

I’m still evaluating if code generation is a better approach (lots of flexibility) but now I have two distinct strategies to generate actions.

My approach is SUPER SIMPLE, I simply take swagger json definition, parse, then generates the activities. I need this approach because we have some specific API behaviour like bearer tokens, special return types, etc. With this approach I have full intellisense 😃

image

If you are insterested, feel free to contact me on my private mail alkampfer@nablasoft.com and I’ll check what details I can share with you.

0reactions
alkampfergitcommented, Jul 28, 2022

You have several options, I’m talking about code generation at compile time, it is really simple and you can simply work with text template where you can simply replace strings and inject in compilation pipeline.

There are various way to obtain this, one is to let NSwag generate a C# client for you, then copy C# code inside your project and let code generator inspect that code and then generate classes.

Or you can simply include json file and let generator work with JSON file.

Actually I’m using an activity provider, because I’ve found problem on my code, code generation can give you more flexibility but is indeed an extra layer of complexity 😃 but I can now choose the technique that suites me most.

Thanks for the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Urgent :( help needed with activities created ...
I need "simple" activity with variable number of params so I'm creating activity using IActivityTypeProvider and placiing parameter values ...
Read more >
With Elsa Workflow 2.0 how to create an activity based on ...
1 Answer. inheriting from HttpEndpoint , it uses an IActivityTypeProvider implementation that dynamically yields new activity types that reuse ...
Read more >
EPiServer.SpecializedProperties
A base class for Properties that wraps a BlockData object. ... PropertyWeekDay. Property that is used to specify one or several weekdays.
Read more >
EPiServer.SpecializedProperties.LinkItemCollection
Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the list that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found