Configuration
Application Settings
For information regarding configuration in the appSettings file, please see AppSettings
Code Configuration
Here is an example of a full, working configuration for JobFlow. Below, we'll go over each piece separately.
builder.Services.AddJobFlow(c =>
{
// Add Jobs database context.
c.AddJobFlowDbContext(o =>
{
o.UseSqlServer(configuration.GetConnectionString("JobsDb"));
});
// Add a Document DTO mapping
// This overload uses the class name as the Document type name
c.ConfigureFlowDefinitions(c => c.Add<MyItem>());
// Add assembly to be scanned for depenency objects
c.AddDependencyAssembly<Startup>();
c.AddDependencyAssembly<NewReminderRule>();
// Add support for using Redis queues
c.AddRedisQueues();
// Add support for Service Bus queues
c.AddAzureServiceBusQueues();
// Use Redis for document storage
c.AddRedisStorageManager();
// Use Azure Storage for document storage
c.AddAzureStorageManager();
// Add NRules processing engine.
c.AddNRulesProcessEngine(r =>
{
// Scan for Rules via reflection in the supplied assemblies
r.AddReflectionRuleLoader(c);
});
});
The AddJobFlow
method adds all the basic required services for JobFlow, allowing for additional configuration of additional modules.
JobFlow DbContext
t
// Add Jobs database context.
c.AddJobFlowDbContext(o =>
{
o.UseSqlServer(configuration.GetConnectionString("JobsDb"));
});
JobFlow uses Entity Framework Core for storage of key data structures. The DbContext configuration is the standard Entity Framework configuration - you're free to pick any EF-compatible storage backend, provided it supports relational querying.
Flow Configurations
// Add a Flow definition
// This overload uses the class name as the Document type name
c.ConfigureFlowDefinitions(c => c.Add<MyItem>());
Every Document requires a mapping to a concrete type. The mapping is performed when the document is loaded from the data store and supplied to the rules. The rules can then match to the specific typed Document - for example, in this case, rules could match to Document<MyItem>
and access and properties in MyItem
.
In the above code, we're explicitly stating that mapping in the configuration, though attributes are available as well. Overloads for the Add
method include:
Add<T>()
- adds the type mapped to the name of the typeAdd<T>(string)
- add the type mapped to the specified nameAdd(string, Type)
- adds the type mapped to the specified name, but non-genericAdd(FlowDefinition)
- adds the full FlowDefinition mapping
The first three overloads are able to take an additional optional parameter of FlowDefinitionSettings which provides additional configuration parameters.
See ConfigureFlowDefinitions and FlowDefinitionConfiguration.
DocumentTypeAttribute
Another option for specifying the document type mapping is to use the attribute DocumentTypeAttribute
.
//[DocumentType("SomeOtherName")]
[DocumentType]
public class MyItem
{
}
To have JobFlow scan for this type, the assembly must be added as a Dependency Assembly (discussed as part of the main JobFlow configuration).
Dependency Assemblies
// Add assembly to be scanned for dependency objects
c.AddDependencyAssembly<Startup>();
c.AddDependencyAssembly<NewReminderRule>();
Assemblies added with the AddDependencyAssembly
method will be scanned for various items:
- Services - any services marked with the
[DependencyService]
attribute - Document Types - any type mappings marked with the
[DocumentType]
attribute - Job Dispatchers - any services marked with the
[JobDispatcher]
attribute - Message Handlers - any services marked with the
[MessageHandler]
attribute
The generic type parameter in the AddDependencyAssembly
method can be any type within the assembly that's to be scanned.
Transports
// Add support for using Redis queues
c.AddRedisQueues();
// Add support for Service Bus queues
c.AddAzureServiceBusQueues();
Any number of transport implementations can be added to the configuration. Workers listen to the queues to pick up work.
See also:
- Transport Listener Configuration - Setting up a background worker in ASP.Net to listen to a transport.
- Azure Function Deployment - Setting up Azure Functions for processing worker messages and core messages.
- AppSettings Transport Configuration - AppSettings items for Transports.
Storage Manager
// Use Redis for document storage
c.AddRedisStorageManager();
// Use Azure Storage for document storage
c.AddAzureStorageManager();
Adds storage systems to use. If more than one storage system is added, then each Flow must define the storage to use, or a default must be configured.
For more information, see:
Flow Processing Engine
// Add NRules processing engine.
c.AddNRulesProcessEngine(r =>
{
// Scan for Rules via reflection in the supplied assemblies
r.AddReflectionRuleLoader(c);
});
Only NRules is supported as a Flow processing engine at the moment. This method allows further configuration of the engine. The ReflectionRuleLoader
will load rules via standard reflection. When using the overload we use here, the same dependency assemblies added to the main JobFlow configuration are scanned. Other loaders, including for other rules definition languages like PowerShell, are planned.