This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
evaluationenginemodules.html
62 lines (60 loc) · 2.03 KB
/
evaluationenginemodules.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
layout: documentation
title: EvaluationEngine
teaser: Decouple business logic from control flow
navigation:
- name: Overview
link: evaluationengine.html
- name: Tutorial
link: evaluationenginetutorial.html
- name: Modules
link: evaluationenginemodules.html
- name: Hierarchical Evaluation Engines
link: evaluationenginehierarchies.html
- name: Aggregators
link: evaluationengineaggregators.html
- name: Expressions
link: evaluationengineexpressions.html
- name: Strategies
link: evaluationenginestrategies.html
- name: Validation
link: evaluationenginevalidation.html
- name: Logging
link: evaluationenginelogging.html
- name: Tips and Tricks
link: evaluationenginetipsandtricks.html
- name: Specifications
link: evaluationenginespecifications.html
---
<h2>Modules</h2>
<p>
Modules are used to load solution definitions in a modular way.
If your dependency injection container for example allows you to acquire all classes implementing IEvaluationEngineModule,
you can use the container to load all definitions from all your code and plug-ins automatically.
</p>
<h3>Define a Module</h3>
<p>
A module is defined by implementing <code>IEvaluationEngineModule</code>:
</p>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
private class FruitModule : EvaluationEngineModule
{
protected override void Load()
{
this.Solve<HowManyFruitsAreThere, int>()
.ByEvaluating(q => new FruitCountExpression { Kind = "Ananas", NumberOfFruits = 17 });
}
}
]]></script>
<p>
When a solution is defined in several places in the code, make sure that the aggregator is only defined once.
In a plug-in system, I suggest you define the strategy and aggregator somewhere in the core.
And the modules only add expressions.
</p>
<h3>Load Module into Evaluation Engine</h3>
<p>
Modules are loaded into the evaluation engine by calling <code>Load</code>:
</p>
<script type="syntaxhighlighter" class="brush: csharp"><![CDATA[
evaluationEngine.Load(new FruitModule());
]]></script>