Application of service components in business logic

zhaozj2021-02-16  76

Here, a three-layer example is used to illustrate the application in service components in business logic. Business Operation: Delete the product and delete the product's quote.

First, see the declaration of the data layer:

Transaction (TransactionOption.supported)]

Public dbobject: servicedcomponent {

}

Public products (): dbObject {public void delete (int productID) {// ...}}

Public price (): dbobject {public void deletebyProductId (int product) {// ...}}

DBObject is the base class of the data object, inherited from servicedcomponent, data objects only supports transactions, and the purpose is to place the transaction's control over the business layer, thereby better controlling business logic. At the same time, the data objects can also be accessed without the operation of business support.

Let's see the statement of the business layer:

[Transaction (TransactionOption.Required)]

Public Productco: ServicesDComponent {

Public void delete (int productID) {

Try {

(New product ()). delete (ProductID);

(new price ()). deletebyProductId (ProductID);

Contextutil.setComplete ();

}

Catch (Exception E) {

Contextutil.Setabort ();

Throw e;

}

}

}

Productco is a product control object, but also inherits from ServicesDComponted, it requests a transaction. When the operation is successful, the transaction is submitted and the transaction is turned back.

转载请注明原文地址:https://www.9cbs.com/read-15644.html

New Post(0)