Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat types of code are appropriate for the service layer?
    text
    copied!<p>Assume you have entities, a service layer, and repositories (with an ORM like NHibernate). The UIs interact with the service layer.</p> <h2><strong>What types of code are appropriate for the service layer?</strong></h2> <hr> <p><strong><em>Repository Coordination?</em></strong></p> <p>It looks like <a href="https://stackoverflow.com/questions/827670/is-it-ok-for-entities-to-access-repositories">entities should not reference the repository</a> so should calls for loading/saving/evicting entities exist in the service layer?</p> <p><strong><em>Business Logic that Involves Repositories?</em></strong></p> <p>If the above is true, should something like checking if a username is distinct go in the service layer (i.e. call GetUsersByUsername and check the results)? Before suggesting that the DB should handle distinct, what about verifying that a password hasn't been used in 90 days?</p> <p><strong><em>Business Logic that Involves Multiple Entities?</em></strong></p> <p>I'm not sure about this one, but say you have the need to apply an operation against a collection of entities that may or may not be related and is not really applicable to a single entity. Should entities be capable of operating on these collections or does this sort of thing belong in the service layer?</p> <p><strong><em>Mapping?</em></strong></p> <p>Whether you use DTOs or send your entities to/from your service layer, you will likely end up mapping (preferably with AutoMapper). Does this belong in the service layer?</p> <hr> <p>I'm looking for confirmation (or rejection) of the ideas listed above as well as any other thoughts about the responsibilities of a service layer when working with entities/repositories.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload