nhibernate - Advice data acces pattern without repository -
i want access isession directly application services (without using repository (http://ayende.com/blog/3955/repository-is-the-new-singleton)) application services unit test hard , nhibernate data access code increase complexity of code (no repository mock , don't want mock repository or in memory db sqllite testing)
is there efficient way access isession service layer?
i use sessionhelper holds isessionfactory - , have methods this:
public t wrapqueryintransaction<t>(func<isession, t> query) { using (var tx = session.begintransaction()) { try { var result = query(session); tx.commit(); return result; } } } i have similar methods common functionality - ie. xxxupdaters loads object in question, makes updates , closes isession again.
and usage follows queries:
var entities = _sessionhelper.wrapqueryintransaction(s => s.queryover<someentity>().list()); for complex queries have these incapsulated in query class can thrown @ sessionhelper.
it works me - hope can use it.
Comments
Post a Comment