My favorite NHibernate exception
We have a rather large, connected domain model, so we use quite a bit of lazy loading to deal with the richness all these connections provide. The one thing I would have liked C# to get from Java is “virtual by default”, if only for one selfish reason: so I don’t see this exception ever, ever again:
_The following types may not be used as proxies:
Project.Domain.Model.Customer: method GetFavorites should be ‘public/protected virtual’ or ‘protected internal virtual’_
I always forget to mark members as virtual, and I still haven’t hunted down all of the templates and code snippets that spit out class members and fixed them. “Virtual by default” isn’t just about testability. It’s about the false assumption that we can predict exactly how end users want to use our API.