using proxies in vb.net with public events

75 views
Skip to first unread message

Eric Bock

unread,
Jan 29, 2009, 11:42:01 AM1/29/09
to nhu...@googlegroups.com
I've persuaded the other developers I work with to give NHibernate a chance.
However, I'm running into an issue after updating some sample projects to
NHibernate 2 (trunk). The proxy type validation logic wants all of my
public methods to be virtual. My class has a public event:

Public Class Building
Implements IBuilding, INotifyPropertyChanged

Public Event PropertyChanged(ByVal sender As Object, ByVal e
As PropertyChangedEventArgs) Implements
INotifyPropertyChanged.PropertyChanged
End Class

The proxy validation returns these error:

BusinessObjects.Building: method add_PropertyChanged should be
'public/protected virtual' or 'protected internal virtual'
BusinessObjects.Building: method remove_PropertyChanged should be
'public/protected virtual' or 'protected internal virtual'

In C# I'd just declare the event virtual, but vb.net doesn't allow
Overridable (virtual) events.

I don't think I can alter my company's decision to standardize on vb.net.
It looks like my other options are:

Stay at NHibernate 1.2
Turn off proxy validation ( <property
name="use_proxy_validator">false</property> )
Stop using proxies
Look into static proxies (
http://ayende.com/Blog/archive/2008/10/10/nhibernate-amp-static-proxies.aspx
)


Any advice? Am I missing an option?


Thanks

Eric Bock

Ken Egozi

unread,
Feb 9, 2009, 8:55:13 AM2/9/09
to nhusers
hmm strange VB ...

you might want to take a look at mapping your entity as an interface
(then you don't have to virtualise all methods).

Fabio has written about it on his blog. can't recall the exact link
though.

and there's also this (wee bit old but can give you a hint):
http://blogs.chayachronicles.com/sonofnun/archive/2007/06/26/251.aspx
>         Look into static proxies (http://ayende.com/Blog/archive/2008/10/10/nhibernate-amp-static-proxi...

Fabio Maulo

unread,
Feb 9, 2009, 9:05:24 AM2/9/09
to nhu...@googlegroups.com
Or you can write your ProxyFactoryFactory implementation overriding the ProxyValidator and then create a JIRA attaching the patch.
You can even disable the proxy validator trough nh-configuration
<property name="use_proxy_validator">false</property>

2009/2/9 Ken Egozi <ego...@gmail.com>



--
Fabio Maulo

Eric Bock

unread,
Feb 9, 2009, 12:41:23 PM2/9/09
to nhu...@googlegroups.com

Thanks Ken and Fabio, I’ll look into both options.

 

Fabio, are you suggesting that my ProxyFactoryFactory implementation return an IProxyValidator that doesn’t validate that the compiler generated add_X and remove_X accessors for an event are virtual? 

 

Thanks,

Eric Bock

Fabio Maulo

unread,
Feb 9, 2009, 5:33:33 PM2/9/09
to nhu...@googlegroups.com
2009/2/9 Eric Bock <eric...@gmail.com>

Thanks Ken and Fabio, I'll look into both options.

 

Fabio, are you suggesting that my ProxyFactoryFactory implementation return an IProxyValidator that doesn't validate that the compiler generated add_X and remove_X accessors for an event are virtual? 


Yes. And when you have it working for certain events-methods create a JIRA and attach the patch. We will review the patch.



--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages