|
1 | 1 | # Light Chain
|
2 | 2 |
|
3 |
| -Lightweight library for implementing simplified version of |
4 |
| -[chain of responsibility](https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern) |
5 |
| -in C#. |
| 3 | +Lightweight library for implementing simplified version of [chain of responsibility](https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern) in C#. |
6 | 4 |
|
7 |
| -The inspiration for this library came from figuring out a way to break up |
8 |
| -`if/else` chains into loosely coupled, separate units to improve maintainability |
9 |
| -through separation of concerns. |
| 5 | +The inspiration for this library came from figuring out a way to break up `if/else` chains into loosely coupled, separate units to improve maintainability through separation of concerns. |
10 | 6 |
|
11 | 7 | Example of `if/else` chain:
|
12 | 8 |
|
@@ -37,10 +33,7 @@ public class Main
|
37 | 33 | }
|
38 | 34 | ```
|
39 | 35 |
|
40 |
| -As we can see from the example, all the blocks of conditions and processing are |
41 |
| -stuck together in the `if/else` construct within the same class. The `if/else` |
42 |
| -construct itself adds a bit of noise. It is difficult to view and change high |
43 |
| -level concerns only, such as order of each case. |
| 36 | +As we can see from the example, all the blocks of conditions and processing are stuck together in the `if/else` construct within the same class. The `if/else` construct itself adds a bit of noise. It is difficult to view and change high level concerns only, such as order of each case. |
44 | 37 |
|
45 | 38 | # Getting Started
|
46 | 39 |
|
@@ -155,17 +148,13 @@ public class Main
|
155 | 148 | }
|
156 | 149 | ```
|
157 | 150 |
|
158 |
| -Be aware that the order of the processors in the list matters: the first |
159 |
| -processor whose condition returns `true` will handle returning the output. |
| 151 | +Be aware that the order of the processors in the list matters: the first processor whose condition returns `true` will handle returning the output. |
160 | 152 |
|
161 | 153 | ### Dependency Injection
|
162 | 154 |
|
163 |
| -Using a dependency injection framework, the processor list and chain instance |
164 |
| -can be defined separately from the main class via the dependency injection |
165 |
| -framework. |
| 155 | +Using a dependency injection framework, the processor list and chain instance can be defined separately from the main class via the dependency injection framework. |
166 | 156 |
|
167 |
| -Using Microsoft.Extensions.DependencyInjection the `Main` class can be |
168 |
| -refactored: |
| 157 | +Using Microsoft.Extensions.DependencyInjection the `Main` class can be refactored: |
169 | 158 |
|
170 | 159 | ```c#
|
171 | 160 | using LightChain;
|
@@ -217,8 +206,7 @@ internal static class ServiceRegistrations
|
217 | 206 | }
|
218 | 207 | ```
|
219 | 208 |
|
220 |
| -The end result is improved separation of concerns such that the main class no |
221 |
| -longer needs to change due to any modifications related to processors: |
| 209 | +The end result is improved separation of concerns such that the main class no longer needs to change due to any modifications related to processors: |
222 | 210 |
|
223 | 211 | - Adding or removing processors from the chain.
|
224 | 212 | - Reordering processors in the chain.
|
|
0 commit comments