Actually I might look at creating an IUnitOfWork which is injected my
ISessionSource, then I can inject an IUnitOfWork to my Services. I
think this might be a better solution.


Cheers
Stefan

On Fri, Nov 21, 2008 at 11:28 AM, Stefan Sedich <[EMAIL PROTECTED]> wrote:
> Hello,
>
> Just a question and advice on how you handle transactions in your
> applications. Currently I have an ISessionSource that has a GetSession
> method like so:
>
> public interface ISessionSource {
>    ISession CreateSession();
> }
>
> I inject this into my repository using Windsor, my implementation
> returns a per request session when CreateSession is called.
>
>
> Now my repository uses this to get the current session, now in my
> service update method I do something like the following:
>
>
> Update(Customer customer) {
>    this.customerRepository.Update(customer);
> }
>
>
> Which works fine, I am getting to the case where I would like to write
> to another repository that is unrelated and have the two calls wrapped
> in a transaction, say writing to a log (NO I am not writing to a log
> table but it is just the simplest example I could think of).
>
> Update(Customer customer) {
>    this.customerRepository.Update(customer);
>    this.logRepository.Insert(logItem);
> }
>
> Now the idea was to inject my ISessionSource into my SERVICE and do
> something like this:
>
> Update(Customer customer) {
>    using(var tx = this.sessionSource.BeginTransaction()) {
>       this.customerRepository.Update(customer);
>       this.logRepository.Insert(logItem);
>       tx.Commit();
>    }
> }
>
>
> Would you be injecting the session manager into the service like this
> or is there a neater way to do this, I cannot see any issues but just
> wanting to get some oppinions on how other people would handle this.
>
>
>
> Cheers
> Stefan
>
> --
> Stefan Sedich
> Software Developer
> http://weblogs.asp.net/stefansedich
>



-- 
Stefan Sedich
Software Developer
http://weblogs.asp.net/stefansedich

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to