c# - ORM Repository Pattern -
this more of question looking opinions. working on project uses both nhibernate , entityframework (this design, wanted flexibility). so, went ahead , started working on repository pattern, came across slight dilemma.
basically, wanted know guys think following areas:
should repository singleton? - allow me keep sessions opened, @ same time, think it's going keep connections opened database. nhibernate, orm can gurantee objet same within same session. ideal easy coding, there definatly ways overcome using keys , overriding gethashcode , equals methods.
if it's not singleton (or if is), should closing connections used? nhibernate, means closing session each time repository "disposed", after every use.
have implemented repository pattern either nhibernate or ef 4.0 , found useful ideas?
don't code creation of singletons (ie singleton pattern itself), use ioc framework structuremap handle lifecycle management of objects.
this can't answer. if it's singleton must thread safe in regards resources manages internally (like connection pool of db live connections). threadsafe code isn't trivial.
this can't answer. depends on how act model. depends whether want people able read through datareader requires active connection database. affects things lazy loading requires active sessions becomes nightmare databinding.
here's i've come in regards creating repository pattern nh: creating common generic , extensible nhiberate repository version 2
Comments
Post a Comment