Transparent Proxy is a rapid development feature eliminating the need to author commands and queries. The proxy acts like an instance of your model. It intercepts method calls and maps to command and query objects of type ProxyCommand
and ProxyQuery
which are then passed to an instance of IEngine
.
The easiest way to create a proxy is using Db.For<T>()
.
Which is actually just short for:
Here’s what’s happening under the hood:
ProxyCommand
containing the method signature and argumentsIEngine<T>
instance owned by the proxyThe exact same thing happens with queries, except ProxyQuery
is used
The proxy has the same type as the model, but not all members are supported. The following rules apply:
Void methods are interpreted as commands, non-void methods as queries. If a command method is non-void it must be tagged with a CommandAttribute
, otherwise it will be interpreted as a query.
If your command or query returns results that don’t need to be cloned, use the CloneResult
property:
Make sure that method input and output (arguments and return value) is serializable.
Just because it’s easy doesn’t mean you can pretend every method call is local. Prefer a chunky over a chatty interaction between your client code and proxy.
Remember that objects returned from queries are copies. The following code will not work as intended because the object returned by GetReminder()
is a copy of the real object.
Prior to verion 0.18, overloads were not supported. Only method names were used to identify method calls. If you introduce overloads to system with journal entries created prior to v0.18, you must use IsDefault
on the original method.
Commands and queries are mapped to ProxyCommand
and ProxyQuery
objects. You can map to user defined types with the MapTo property. The type must have a constructor taking the same arguments as the method.
To exclude a method from being proxied, add a NoProxy
attribute:
Properties in NET are just syntactic sugar. Getters and setters are compiled into methods. Everything that applies to methods apply to setters and getters as well. This means you can use the attributes described above on setters and getter of properties and indexers:
NoProxy
‘Can also be applied to a properties getter or setter: