Skip to content

Commit e432405

Browse files
committed
readme
1 parent a1e7f3a commit e432405

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

src/samples/WebApiSample/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
# Using with ASP.NET Core
3+
4+
This sample will use `docker-compose` to fire up instances of MongoDB and Elasticsearch to which the sample application will connect.
5+
6+
## How to configure within an ASP.NET Core application
7+
8+
In your startup class, use the `AddWorkflow` extension method to configure workflow core services, and then register your workflows and start the host when you configure the app.
9+
```c#
10+
public class Startup
11+
{
12+
public Startup(IConfiguration configuration)
13+
{
14+
Configuration = configuration;
15+
}
16+
17+
public IConfiguration Configuration { get; }
18+
19+
public void ConfigureServices(IServiceCollection services)
20+
{
21+
services.AddMvc();
22+
services.AddWorkflow(cfg =>
23+
{
24+
cfg.UseMongoDB(@"mongodb://mongo:27017", "workflow");
25+
cfg.UseElasticsearch(new ConnectionSettings(new Uri("http://elastic:9200")), "workflows");
26+
});
27+
}
28+
29+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
30+
{
31+
if (env.IsDevelopment())
32+
{
33+
app.UseDeveloperExceptionPage();
34+
}
35+
36+
app.UseMvc();
37+
38+
var host = app.ApplicationServices.GetService<IWorkflowHost>();
39+
host.RegisterWorkflow<TestWorkflow, MyDataClass>();
40+
host.Start();
41+
}
42+
}
43+
```
44+
45+
## Usage
46+
47+
Now simply inject the services you require into your controllers
48+
* IWorkflowController
49+
* IWorkflowHost
50+
* ISearchIndex
51+
* IPersistenceProvider
52+
53+
```c#
54+
public class WorkflowsController : Controller
55+
{
56+
private readonly IWorkflowController _workflowService;
57+
private readonly IWorkflowRegistry _registry;
58+
private readonly IPersistenceProvider _workflowStore;
59+
private readonly ISearchIndex _searchService;
60+
61+
public WorkflowsController(IWorkflowController workflowService, ISearchIndex searchService, IWorkflowRegistry registry, IPersistenceProvider workflowStore)
62+
{
63+
_workflowService = workflowService;
64+
_workflowStore = workflowStore;
65+
_registry = registry;
66+
_searchService = searchService;
67+
}
68+
69+
public Task<bool> Suspend(string id)
70+
{
71+
return _workflowService.SuspendWorkflow(id);
72+
}
73+
74+
...
75+
}
76+
```

src/samples/WebApiSample/WebApiSample.sln

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.28307.168
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiSample", "WebApiSample\WebApiSample.csproj", "{14489389-A65D-4993-8DE2-F51701A5AF60}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiSample", "WebApiSample\WebApiSample.csproj", "{14489389-A65D-4993-8DE2-F51701A5AF60}"
77
EndProject
88
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{2D5D708D-7EA1-48A9-ABF0-64CCC6026435}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6545FD2F-EBA5-4C65-8257-2C1E34AD2FAA}"
11+
ProjectSection(SolutionItems) = preProject
12+
README.md = README.md
13+
EndProjectSection
14+
EndProject
1015
Global
1116
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1217
Debug|Any CPU = Debug|Any CPU

src/samples/WebApiSample/WebApiSample/Controllers/WorkflowsController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public WorkflowsController(IWorkflowController workflowService, ISearchIndex sea
2828
_registry = registry;
2929
_searchService = searchService;
3030
}
31-
32-
31+
3332
[HttpGet]
3433
public async Task<IActionResult> Get(string terms, WorkflowStatus? status, string type, DateTime? createdFrom, DateTime? createdTo, int skip, int take = 10)
3534
{

0 commit comments

Comments
 (0)