Hi

I have a problem on how to span a transaction over multiple business classes
without using COM+

Example:
A existing person get an MailingAddress assigned to

public class PersonService
{
public void InsertMailingAddress(data)
{
//ask the AddressService to insert an address
new AddressService().InsertAddress();

//update the person with the ID from the newly inserted address
}
}

As you can see, this should be in a transaction --> Insert Address -->
Update Person
How can i span this in a transaction without passing sqltransaction objects
in the businesslayer?

Any ideas???

RE: Transaction spanning multiple business classes by jch

jch
Wed Jun 01 09:30:01 CDT 2005

There is no simple way to do this - at least not until .net 2.0 is released
(see
http://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dndotnet/html/introsystemtransact.asp).

But there are different patterns to solve this exact problem. One of them
is the "Unit of Work" pattern. I recommend reading Martin Fowlers book:
http://www.martinfowler.com/eaaCatalog/unitOfWork.html

HTH, Jakob.

--
http://www.dotninjas.dk


"Klenne" wrote:

> Hi
>
> I have a problem on how to span a transaction over multiple business classes
> without using COM+
>
> Example:
> A existing person get an MailingAddress assigned to
>
> public class PersonService
> {
> public void InsertMailingAddress(data)
> {
> //ask the AddressService to insert an address
> new AddressService().InsertAddress();
>
> //update the person with the ID from the newly inserted address
> }
> }
>
> As you can see, this should be in a transaction --> Insert Address -->
> Update Person
> How can i span this in a transaction without passing sqltransaction objects
> in the businesslayer?
>
> Any ideas???
>

RE: Transaction spanning multiple business classes by Klenne

Klenne
Wed Jun 01 09:37:20 CDT 2005

Hi Jakob

I know the patterns a little bit but i can't seem to get started

How would i implement this given the scenario i'm in?

Thanks for the help!!!

> > public class PersonService
> > {
> > public void InsertMailingAddress(data)
> > {
> > //ask the AddressService to insert an address
> > new AddressService().InsertAddress();
> >
> > //update the person with the ID from the newly inserted address
> > }
> > }


RE: Transaction spanning multiple business classes by jch

jch
Thu Jun 02 01:43:01 CDT 2005

Implementing UnitOfWork and the related patterns (e.g. datamappers) is
probably not something you can do in a matter of minutes. I have tried
googling for some samples without any luck.

If you are in a hurry and do not have time to read through Fowler's book,
you might just opt for the easy solution and pass a reference to a
transaction object as a parameter. Another fairly easy solution is to
register a transaction object using some kind of Registry pattern and then
let the Insert and Update methods access the registry using a unique ID to
get a hold of the transaction. But the transaction would still have to
started by your business logic. Fowler also describes the Registry solution.

HTH, Jakob.

--
http://www.dotninjas.dk


"Klenne" wrote:

> Hi Jakob
>
> I know the patterns a little bit but i can't seem to get started
>
> How would i implement this given the scenario i'm in?
>
> Thanks for the help!!!
>
> > > public class PersonService
> > > {
> > > public void InsertMailingAddress(data)
> > > {
> > > //ask the AddressService to insert an address
> > > new AddressService().InsertAddress();
> > >
> > > //update the person with the ID from the newly inserted address
> > > }
> > > }
>