Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgerlag committed Jan 31, 2019
1 parent a1e7f3a commit e432405
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
76 changes: 76 additions & 0 deletions src/samples/WebApiSample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

# Using with ASP.NET Core

This sample will use `docker-compose` to fire up instances of MongoDB and Elasticsearch to which the sample application will connect.

## How to configure within an ASP.NET Core application

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.
```c#
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddWorkflow(cfg =>
{
cfg.UseMongoDB(@"mongodb://mongo:27017", "workflow");
cfg.UseElasticsearch(new ConnectionSettings(new Uri("http://elastic:9200")), "workflows");
});
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();

var host = app.ApplicationServices.GetService<IWorkflowHost>();
host.RegisterWorkflow<TestWorkflow, MyDataClass>();
host.Start();
}
}
```

## Usage

Now simply inject the services you require into your controllers
* IWorkflowController
* IWorkflowHost
* ISearchIndex
* IPersistenceProvider

```c#
public class WorkflowsController : Controller
{
private readonly IWorkflowController _workflowService;
private readonly IWorkflowRegistry _registry;
private readonly IPersistenceProvider _workflowStore;
private readonly ISearchIndex _searchService;

public WorkflowsController(IWorkflowController workflowService, ISearchIndex searchService, IWorkflowRegistry registry, IPersistenceProvider workflowStore)
{
_workflowService = workflowService;
_workflowStore = workflowStore;
_registry = registry;
_searchService = searchService;
}

public Task<bool> Suspend(string id)
{
return _workflowService.SuspendWorkflow(id);
}

...
}
```
7 changes: 6 additions & 1 deletion src/samples/WebApiSample/WebApiSample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiSample", "WebApiSample\WebApiSample.csproj", "{14489389-A65D-4993-8DE2-F51701A5AF60}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiSample", "WebApiSample\WebApiSample.csproj", "{14489389-A65D-4993-8DE2-F51701A5AF60}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{2D5D708D-7EA1-48A9-ABF0-64CCC6026435}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6545FD2F-EBA5-4C65-8257-2C1E34AD2FAA}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public WorkflowsController(IWorkflowController workflowService, ISearchIndex sea
_registry = registry;
_searchService = searchService;
}



[HttpGet]
public async Task<IActionResult> Get(string terms, WorkflowStatus? status, string type, DateTime? createdFrom, DateTime? createdTo, int skip, int take = 10)
{
Expand Down

0 comments on commit e432405

Please sign in to comment.