I believe we can give credit to Jimmy Nilsson for creating in the term
in ADDDP (Applying Domain Driven Design and Patterns).
You could use nhibernate in a more classic repository implementation
(DAO layer) and not run into these issue with your proxies.
There are many other issues with nhibernate and PI ... my personal
largest one is the lack of support for constructor mapping which can
really screw with validation stories but again I can work around this
in the same way I can with EF, I can use DAOs and put a repository
over the top of them.
Cheers,
Greg
--
It is the mark of an educated mind to be able to entertain a thought
without accepting it.
> So does NH really achieve Persistence Ignorance?
IMNSHO it's a dumb idea to try to make your business layer completly
persistence ingnorant (in the way you suggest), because there is some
persistence in the background and you are developing a complex
system. Having really pure POCOs with absolut none constraints, where
you program as if no persitence exists, is like having a team of
a hundred developers writing code with no constraints (at least no
coding conventions) and hoping all will be well, working, and good
looking in the end.
Complex systems needs decisions and constraints and conventions. There
are very important. And especially the heart of your system is
influenced by these decisions and constraints. Deal with it!
The crucial idea of presistence ignorance is to try to help to make
clear decisions. You should not use NHibernate and ISessions all over
your code -- but this is not because otherwise it would be so easy to
exchange your ORM (it never is), but because you need this to better
structure your software, because otherwise you have no chance of ever
get this complex system really working (not to mention to adapt the
system for future changes).
So NHibernate requires some constructors or all properties virtual?
Never mind. Rules of thumb like persistence ignorance should guide
you, they are not strict laws and you won't be shot if you follow
common sense. :)
--
Until the next mail...,
Stefan.
Now you ask me for a patch.
hmm.
Cheers,
Greg
but it DOES:
+ Force me to make all of my methods and properties virtual, for the
use of proxies
+ Force me to override Equals() and GetHashCode(), because of proxies
+ Prevent me from putting logic in public property getters/setters,
because the proxies, upon hydrating objects, would incorrectly execute
that logic.
+ Create the "polymorphic databinding" problem with lists and
collections of objects, because of proxies.
If you want I have the only one unsolvable intrusion
With NH you must have an ID as your POID even if your Entity don't need it
P.S. well... "I don't want to write a lot of code"... I mean out side NH core.
With a lot of Entity Framework buzz being generated recently, due to
it's v1 release with VS2008 SP1, the term Persistence Ignorance has
been climbing the Google ranks ladder. Indeed, a Google search of the
term shows that of the top 5 results, 3 are about the Entity
Framework. Since I work in an otherwise all Microsoft shop, I am very
interested in the EF, and the recent buzz has caused me to think more
about Persistence Ignorance. Out of the box, EF doesn't have it, but
someone at MS has created a PI POCO adapter for EF v1.
I define all my model entities as interfaces in a separate assembly.
I have a "code generator " that takes care of all the plumbing for me:
1) generates the classes as the storage wants them : NH virtual
methods, primary keys
I define all my model entities as interfaces in a separate assembly.
I have a "code generator " specific for each storage that takes care
of all the plumbing for me:
1) generates the classes as the storage wants them : NH virtual
methods, primary keys,
2) NH mappings
3) registeres the implementation classes with the interfaces so
they are accessible from my IOC
Advantages:
the model is not poluted in any way: no attributes, no id
properties, no reference to any ORM
if i have to change something regarding to persistence i do that in
one place, but not in my "model"
Regarding rules and validations: i use my own rules engine that is
specified against interfaces and "weaved" at runtime.
Regarding : code it yourself advice, this is the biggest pain in the
**** with open source projects that do not have the guts to take
documentation to the level it will make it easy for other folks to
understand and help the project grow.