Skip to content

Commit d3dfa95

Browse files
authored
Merge pull request danielgerlag#161 from Kahbazi/remove_reflection
Remove reflection for creating Data
2 parents 3430a77 + 89d6372 commit d3dfa95

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/WorkflowCore/Interface/IWorkflowController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public interface IWorkflowController
99
{
1010
Task<string> StartWorkflow(string workflowId, object data = null, string reference=null);
1111
Task<string> StartWorkflow(string workflowId, int? version, object data = null, string reference=null);
12-
Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null) where TData : class;
13-
Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null) where TData : class;
12+
Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null) where TData : class, new();
13+
Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null) where TData : class, new();
1414

1515
Task PublishEvent(string eventName, string eventKey, object eventData, DateTime? effectiveDate = null);
1616
void RegisterWorkflow<TWorkflow>() where TWorkflow : IWorkflow, new();

src/WorkflowCore/Services/WorkflowController.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class WorkflowController : IWorkflowController
1818
private readonly IQueueProvider _queueProvider;
1919
private readonly IExecutionPointerFactory _pointerFactory;
2020
private readonly ILogger _logger;
21-
21+
2222
public WorkflowController(IPersistenceProvider persistenceStore, IDistributedLockProvider lockProvider, IWorkflowRegistry registry, IQueueProvider queueProvider, IExecutionPointerFactory pointerFactory, ILoggerFactory loggerFactory)
2323
{
2424
_persistenceStore = persistenceStore;
@@ -40,15 +40,15 @@ public Task<string> StartWorkflow(string workflowId, int? version, object data =
4040
}
4141

4242
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null)
43-
where TData : class
43+
where TData : class, new()
4444
{
4545
return StartWorkflow<TData>(workflowId, null, data, reference);
4646
}
4747

4848
public async Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null)
49-
where TData : class
49+
where TData : class, new()
5050
{
51-
51+
5252
var def = _registry.GetDefinition(workflowId, version);
5353
if (def == null)
5454
{
@@ -69,7 +69,7 @@ public async Task<string> StartWorkflow<TData>(string workflowId, int? version,
6969

7070
if ((def.DataType != null) && (data == null))
7171
{
72-
wf.Data = TypeExtensions.GetConstructor(def.DataType, new Type[] { }).Invoke(null);
72+
wf.Data = new TData();
7373
}
7474

7575
wf.ExecutionPointers.Add(_pointerFactory.BuildGenesisPointer(def));
@@ -102,7 +102,7 @@ public async Task<bool> SuspendWorkflow(string workflowId)
102102
{
103103
if (!await _lockProvider.AcquireLock(workflowId, new CancellationToken()))
104104
return false;
105-
105+
106106
try
107107
{
108108
var wf = await _persistenceStore.GetWorkflowInstance(workflowId);
@@ -169,7 +169,7 @@ public async Task<bool> TerminateWorkflow(string workflowId)
169169
await _lockProvider.ReleaseLock(workflowId);
170170
}
171171
}
172-
172+
173173
public void RegisterWorkflow<TWorkflow>()
174174
where TWorkflow : IWorkflow, new()
175175
{

src/WorkflowCore/Services/WorkflowHost.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace WorkflowCore.Services
1313
{
1414
public class WorkflowHost : IWorkflowHost, IDisposable
15-
{
16-
protected bool _shutdown = true;
15+
{
16+
protected bool _shutdown = true;
1717
protected readonly IServiceProvider _serviceProvider;
1818

1919
private readonly IEnumerable<IBackgroundTask> _backgroundTasks;
@@ -54,14 +54,14 @@ public Task<string> StartWorkflow(string workflowId, int? version, object data =
5454
}
5555

5656
public Task<string> StartWorkflow<TData>(string workflowId, TData data = null, string reference=null)
57-
where TData : class
57+
where TData : class, new()
5858
{
5959
return _workflowController.StartWorkflow<TData>(workflowId, null, data, reference);
6060
}
6161

6262

6363
public Task<string> StartWorkflow<TData>(string workflowId, int? version, TData data = null, string reference=null)
64-
where TData : class
64+
where TData : class, new()
6565
{
6666
return _workflowController.StartWorkflow(workflowId, version, data, reference);
6767
}
@@ -72,7 +72,7 @@ public Task PublishEvent(string eventName, string eventKey, object eventData, Da
7272
}
7373

7474
public void Start()
75-
{
75+
{
7676
_shutdown = false;
7777
PersistenceStore.EnsureStoreExists();
7878
QueueProvider.Start().Wait();
@@ -86,26 +86,26 @@ public void Start()
8686

8787
public void Stop()
8888
{
89-
_shutdown = true;
90-
89+
_shutdown = true;
90+
9191
Logger.LogInformation("Stopping background tasks");
9292
foreach (var th in _backgroundTasks)
9393
th.Stop();
94-
94+
9595
Logger.LogInformation("Worker tasks stopped");
96-
96+
9797
QueueProvider.Stop();
9898
LockProvider.Stop();
9999
}
100-
101-
public void RegisterWorkflow<TWorkflow>()
100+
101+
public void RegisterWorkflow<TWorkflow>()
102102
where TWorkflow : IWorkflow, new()
103103
{
104104
TWorkflow wf = new TWorkflow();
105105
Registry.RegisterWorkflow(wf);
106106
}
107107

108-
public void RegisterWorkflow<TWorkflow, TData>()
108+
public void RegisterWorkflow<TWorkflow, TData>()
109109
where TWorkflow : IWorkflow<TData>, new()
110110
where TData : new()
111111
{

0 commit comments

Comments
 (0)