QInjection is a library for C# Lambda Query Injection.
QInjection means "Query Injection" and it is a pattern I developed to inject a simple lambda expression on web service side ... but you can also use it in all other situations where you need to apply at runtime a lambda expression on a data collection.
QInjection at moment is not a product but a concept, maybe a sort of software mock up, based on
Microsoft Roslyn CTP (Community Technical Preview).
GO TO: https://qinjection.codeplex.com/
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
QInjection (Lambda Query Injection in C# using Roslyn)
1. 1
… in short
SamNium (January 2014) https://qinjection.codeplex.com/
QInjection ... about how to use Roslyn to implement a simple query injection engine
2. 2
How QInjection come from?
It comes from the need to use Microsoft Roslyn in order to evaluate
lambda expressions at service side (of a WCF web Service)
QInjection ... about how to use Roslyn to implement a simple query injection engine
3. 3
Filtering at the client side
Client
Application
Web Service
GetData
Client
Application
Web Service
Client
Application
Web Service
Client
Application
Web Service
Filter
APPLY lambda expression
and take the white ones
QInjection ... about how to use Roslyn to implement a simple query injection engine
4. 4
Filtering at the web service side
Client
Application
Web Service
GetData with lambda expression
Client
Application
Web Service
Client
Application
Web Service
Client
Application
Web Service
Client
Application
Web Service
QInjection ... about how to use Roslyn to implement a simple query injection engine
APPLY
lambda
expression
5. 5
How do you use QInjection?
You have to implement a class that act as Data Provider Bridge of the data
collection, this class have to implement the interface IQProvider<T> where T is the
type of the items (integer in this example)
You have to instantiate the QInjector object and then:
Define the validation RULE
Validate the expression
Execute the expression on your Data Provider Bridge (this one will act as container of the
runtime injected code).
QInjection ... about how to use Roslyn to implement a simple query injection engine
6. 6
Three phases
Define
Define Syntax of
the lambda
expression to
accept as input.
QInjection ... about how to use Roslyn to implement a simple query injection engine
Validate
Validate the
lambda
expression by
using its AST
representation.
Evaluate
Evaluate lambda
expression on
your code.
8. 8
Looking at the Validation Facilities
User Code
Aggregate
Validation Rule
Facilities
Low Level
Vlidation Rule
Facilities
Support
As
WithName
WithNameRegex
WithArity
WithOperator
RefuseReference
Accept
AcceptNames
AcceptOperators
AcceptArities
Core
Validation
&
Scripting
QInjection ... about how to use Roslyn to implement a simple query injection engine
Validate
9. 9
How QInjection works?
QInjection is based on Microsoft Roslyn both for Validation and
Scripting.
QInjection ... about how to use Roslyn to implement a simple query injection engine
10. 10
VALIDATE
EVALUATE
The expression is translated in an
AST representation.
An internal TreeValidator engine
go through the AST and checks
the Links between Branches and
evaluates if the Validation Rules
on Nodes are satisfied.
If the expression is valid then an
internal engine inject a Spy
Object inside your Object.
The Spy Object acts as Bridge
between your data provider and
the IEnumerable<T>.Where(…)
method of your data collection.
QInjection ... about how to use Roslyn to implement a simple query injection engine
11. 11
The AST of “x => x == 1”
x => x == 1
Parameter
IdentifierName
Syntax
SimpleLambda
ExpressionSyntax
Left
IdentifierName
Syntax
QInjection ... about how to use Roslyn to implement a simple query injection engine
Body
BinaryExpression
Syntax
RIght
LiteralExpression
Syntax
12. 12
A small look at the Core
<lambda expression>
AST
Map of <Branch, List of Node>
Branch Set
Rule Set
Map of <Node, Map of <Rule, List of Rule Data>>
QInjection ... about how to use Roslyn to implement a simple query injection engine
TreeValidator
Rule Validator