5.5 Serviced Components
Building components and class libraries is a good way to organize your code, but the main advantage of writing class libraries and components for your application is to gain the benefits of COM+ Component Services. With COM+ Component Services, your components can take advantage of automatic transaction processing, object pooling, and role-based security. Components that use COM+ Component Services are called serviced components.
Setting up a component to take advantage of these features is not difficult. It requires creating a class library project as shown earlier plus creating several component classes to handle the business logic. Let's discuss an example scenario that uses serviced components.
Suppose that we are writing an ordering and inventory system for a supermarket. The system will track inventory as well as receive orders. Three different types of users will work with this system: Suppliers, Supervisors, and Receiving Clerks. Suppliers enter any orders that we expect to receive into our database. Any products that are ordered must be products that the store normally carries. Supervisors are authorized to add new product types to the database. Receiving Clerks and Supervisors are authorized to receive orders. Line items received from an order will be immediately reflected as available inventory for the supermarket. Figure 5-6 shows the database schema used for the ordering and inventory system, showing tables, columns, and foreign key relationships among columns. (Note that this system is simplified for the purposes of the example.) To run the code samples, you will need to create a SQL Server database with these specifications, tables, and relationships. Tables 5-3 through 5-6 list the table column names and data types for the four tables shown in Figure 5-6.
Figure 5-6 Database diagram of a supermarket ordering and inventory system
Table 5-3 Column Names and Data Types for the Inventory Table
Column Name |
Data Type |
BinNumber |
Varchar(255) |
SKU |
Varchar(255) |
Quantity |
Int |
Table 5-4 Column Names and Data Types for the Product Table
Column Name |
Data Type |
SKU |
Varchar(255) |
Description |
Varchar(255) |
UnitPrice |
Decimal |
StockingBinNumber |
Varchar(255) |
Table 5-5 Column Names and Data Types for the Orders Table
Column Name |
Data Type |
OrderNumber |
Varchar(255) |
SupplierName |
Varchar(255) |
OrderReceived |
Bit |
Table 5-6 Column Names and Data Types for the OrderDetails Table
Column Name |
Data Type |
OrderNumber |
Varchar(255) |
LineItemNumber |
Int |
SKU |
Varchar(255) |
QuantityReceived |
Int |
Quantity |
Int |
ID |
Identity |
TIP
Consult your SQL Server documentation about creating a new database and setting up tables if you are not familiar with the process. Recruit the help of a database administrator if you need assistance in obtaining authorization to create a database (if you're in an enterprise/shared database environment). We will discuss database access in detail in Chapter 7.