c# - Using dynamic proxy on NHibernate objects -


I'm trying to use Castle. Dynamic Proxy 2 under clean up code under NHibernate permanent sections. Here's a simple version.

PET class:

  public class stomach {public entry ID (get; set;} public string name {get; set;} public int age {receipt; set ;}}  

and its mapping file:

  & lt; class name = "pet" table = "pet" & gt; & lt; id Name = "id" column = "id" not saved-value = "0" & ​​gt; Generator class = "parent" />  gt; & lt; property Name = "name" column = "name" /> property name = "age" column = "age" />   

Pet Generally, the name and age of the properties will not be automatic properties and there will be logic to record the value changes. Now, I have to type in the proxy for injecting auditing logic To do this, I created an auditor II interceptor:

  public class auditor: IInterceptor {public nullivation (IInvocation invocation) {// changes Do something to record movement. Proceed (); }}  

Creating an audited example of a pet class is very easy using castles. Dynamic Proxy 2

  Pet Epit = Proxy Generator. Crelet Class Proxy & Lt; Pet> (new auditor ()); Apet.Name = "muffles"; // Auditor Examples will record this. APet.Age = 4; // And also ...  

Now there is a problem. As the stomach is continuous, the system has to work on instances of bringing pets through NIBNET. What I want to do is that NHibernate has to automatically return the pet proxy incidents:

  // I imagine that an example of an auditor is ICRITI criteria = creation . Crateratratia (typef (pet)); Criterion Add (expression expression.a ("name", "muffles")); // Returns the list of stomach proxy in lieu / so changes can be recorded. IList & LT; Pet & gt; Results = Criteria. List & lt; Pet & gt; (); Pet Appetizer = Result [0]; APet.Age = aPet.Age + 1; // I hope the proxy is still a pet example session since it was successful. Save (aPet);  

Something has been done to bring me around this:

  Icricetia criteria = session. Creatitrix (Proxy Heller. GETPROXY Type Type  ()); Criterion Add (expression expression.a ("name", "muffles")); // instead of the list () instead of the list & lt; T & gt; () // and IList instead of IList & lt; Pet & gt; IList result = criteria. List ();  

Where ProxyHelper.GetProxyType & lt; Pet & gt; () will return the cached pet proxy type. The main disadvantage is that this solution will not work on general lists (such as IList & lt; Pet & gt; ). The current system I'm trying to clean uses them extensively.

So I hope someone has an alternative solution or has no insights or not what I am doing or not.

Thanks a million,

Carlos

you use

Hitch these hooks and events in NHibernate's event system

The link actually shows an auditing app example.

This could be a better idea than using a proxy.

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -