imo, transactions should be handled in the app layer (controller in MVC or
MessageHandler in SOA) and not in the services/repositories
On Fri, Nov 21, 2008 at 9:49 AM, Symon Rottem <[EMAIL PROTECTED]> wrote:
> Have you considered using the Castle Transacation Management Facility since
> you're using both NH and Windsor?
>
> Cheers,
>
> Symon.
>
>
> On Fri, Nov 21, 2008 at 3: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
>>
>>
>>
>
>
> --
> Symon Rottem
> http://blog.symbiotic-development.com
>
>
> >
>
--
Ken Egozi.
http://www.kenegozi.com/blog
http://www.delver.com
http://www.musicglue.com
http://www.castleproject.org
http://www.gotfriends.co.il
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---