d.Service Layer

  1. Motivation
    1. To write a webservice wrapper over business logic usually for out of process communication.
  2. Summary
    1. A Service Layer defines an application's boundary and its set of available operations from the perspective of interfacing client layers. 
    2. It encapsulates the application's business logic, controlling transactions and coordinating responses in the implementation of its operations.
    3. A business logic is usually of two type Domain Logic (Core Business Components like business rules) and application logic like notification service and service layer in general  expose the application logic as out process service.

  3. When to Use
    1. When you need to expose application logic (businesss logic=Domain Logic+application Logic) as a saparate subsystem mostly out of proc.
  4. Implementation
    1. The two basic implementation variations are the domain facade approach and the operation script approach.
    2. Domain Facade
      1. In the domain facade approach a Service Layer is implemented as a set of thin facades over a Domain Model.
      2. The classes implementing the facades don't implement any business logic. 
      3. The thin facades establish a boundary and set of operations through which client layers interact with the application, exhibiting the defining characteristics of Service Layer. 
    3. Operation Script
      1. In the operation script approach a Service Layer is implemented as a set of thicker classes that directly implement application logic but delegate to encapsulated domain object classes for domain logic. 
      2. The operations available to clients of a Service Layer are implemented as scripts, organized several to a class defining a subject area of related logic. 
      3. Each such class forms an application "service," and it's common for service type names to end with "Service." A Service Layer is comprised of these application service classes, which should extend a Layer Supertype, abstracting their responsibilities and common behaviors.
  5. Example 
    1. TODO
  6. Related Patterns
    1. Domain Model
    2. Transaction Scripts
  7. Specific Considerations
    1. Remote Vs Local 
      1. Preferable we should start working on service layer implementation that directly invoke business object.
      2. Ten prefer to write a thin facade on local layer applications and clients that needs to access it out of proc.
      3. This allow in proc application to take advantage of in proc performance.

  8. References
    1. Overview Tutorials 
      1. MSDN:Service Layer Guidelines
    2. Other References
      1. http://martinfowler.com/eaaCatalog/serviceLayer.html