NJection provides a way to inject .NET code at runtime using configuration files.
Through parsing a configuration file an expression tree is built and can be later on
compiled and run, thus, giving the possibility to inject different pieces of code.
Parsing the configuration file is done by using the ExpressionBuilder's Traverse method:
LambdaExpression expression = ExpressionBuilder.Traverse<LambdaExpression>(@"C:\Example.config");
Action<string> actionOfString = expression.Compile() as Action<string>;
actionOfString("Hello World!");
Here we defined a method call to WriteLine of the static class Console.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<expression type="Lambda" typeof="System.Action`1[System.String]">
<expression type="Call" typeof="System.Console" kind="Static" methodName="WriteLine">
<arguments>
<expression ref="valueParameter" />
</arguments>
</expression>
<arguments>
<expression type="Parameter" typeof="System.String" name="valueParameter" />
</arguments>
</expression>
</configuration>
  • Easy configuration paradigm.
  • Configure which code will be executed at runtime.
  • Full managed .NET 4.0 framework code.

Copyright © 2014 Sagi Fogel