transactions - Controlling NHibernate ITransaction with StructureMap? -


I am using StructureMap as my ORM as my IoC container and NHibernate I have found an example online That shows how ISessionFactory and anion is produced with StrapCap, so the factory is a singleton and the session is based on HTTP contact. It works great, but then I started using the NH profiler, in which I was told that I should always use the transaction. So, I thought, why not let StructureMap do the same for me?

Here's how I start StructureMax:

 

  ObjectFactory.Initialize (x => {x.ForRequestedType} & Lt; ISessionFactory & gt; () .CacheBy (InstanceScope.Singleton) by Default.Is.Constructed (cfg.BuildSessionFactory); x.ForRequestedType & lt; ISession & gt; () .CacheBy (Instancescope Hybrid). Default .is.connected (context => gtc: context.getInstance & lt; ISessionFactory & gt; (.) Openness ()) x. Forerexest type & lt; ITRsction & gt; () .CacheBy (InstanceScope.Hybrid) .Default By I.s.Constructed (context => context.GetInstance & lt; ISession & gt; (). Ratishtapan ()); x.Scan (y = & gt; {y. Calling assembly (); y.WithDefaultConventions ();});}); All the repositories look like the following:  
  Public userrepo _transaction = transaction; }  

and looks like a normal method inside the repository:

  remove the public null (int id) {Remove (_session.Get & lt; User & gt; (id)); }  

What I am trying to do are all the ways, which I call in an HTTPTextext is the same session and part of the transaction. Is it possible or is it totally wrong and I am barking the wrong tree?

Thanks in advance!

- dan

This problem was because I created a simple unitoff which Connects the passion and the intractionation.

In the tests, I will write the following code:

  var product = new product {name = "apple", category = "fruits"}; (Var session = _sessionFactory.OpenSession ()) (var transaction = _session.BeginTransaction ()) {session.Save (product); Transaction.Commit (); } When I really wanted:  
  var product = new product {name = "apple", category = "fruits"}; (Var unitOfWork = New Unitofwork (_sessionFactory)) {unitOfWork.CurrentSession.Save (product); UnitOfWork.Commit (); }  

Here is my unit of implementation of the work,

  using NHibernate; Namespace NHibernateBootstrap.Core.Persistence {Public Class UnitOfWork: IUnitOfWork {Private readonly ISessionFactory _sessionFactory; Private readonly iatransaction_transption; Public Unit Office (Foundation Factory Session Factor) {_sessionFactory = sessionFactory; Current session = _sessionFactory.OpenSession (); _transaction = Current session. } The current session of the public warning {received; Private Set;} Public Zero Extraction () {CurrentSession.Close (); Current session = null; } Public Zero Commit () {_transaction.Commit (); As far as using the Commit () (either ITRsaction or Unitofwork), I believe that it should be done clearly before the end of your request. If you do not call it, then the unitofwork should clean itself, but should not be committed. Alternatively, you can use an HTTMDUD to commit to an Android handler. 


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -