Skip to content

Instantly share code, notes, and snippets.

@justinAurand
Created March 30, 2017 19:38
Show Gist options
  • Save justinAurand/3879cbb48bd26aeef9941cce969d6589 to your computer and use it in GitHub Desktop.
Save justinAurand/3879cbb48bd26aeef9941cce969d6589 to your computer and use it in GitHub Desktop.
Getting a workflow runner from a service.
namespace WorkflowActions
{
using System;
internal class Program
{
private static void Main()
{
const string workflowName = "Ftp";
var workflowService = new WorkflowService();
var workflow = workflowService.Get(workflowName);
workflow?.Run();
}
}
public interface IRunnableWorkflow
{
void Run();
}
public interface IWorkflowService
{
IRunnableWorkflow Get(string name);
}
public class Ftp : IRunnableWorkflow
{
public void Run()
{
Console.WriteLine("************************************************Inside FTP");
Console.ReadKey();
}
}
public class WorkflowService : IWorkflowService
{
public IRunnableWorkflow Get(string name)
{
var currentNameSpace = typeof (Program).Namespace;
var type = Type.GetType(currentNameSpace + "." + name);
if (type == null)
return null;
return (IRunnableWorkflow) Activator.CreateInstance(type);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment