Hi nisarkha,
First off thanks for buying my book
http://forums.asp.net/tiny_mce/jscri...iley-smile.gif
Having a look at your code your service class seems a little mixed up. From Fowlers book on Patterns of Enterprise Arch the service layer...
"...defines an application's boundary [Cockburn PloP] and its set of available operations from the perspective of interfacing client layers. It encapsulates the application's business logic, controlling transactions and coor-dinating responses in the implementation of its operations." ~
http://martinfowler.com/eaaCatalog/serviceLayer.html
So I would modify the service layer like so:
Code:
public class EscortService : IEscortService
{
private IEscortRepository _escortRepository;
public EscortService(IEscortRepository escortRepository)
{
_escortRepository = escortRepository;
}
public List<PartialPerson> LoadEscort()
{
// Could cache the response from the repository
// do something else with the list of PartialPerson
return _escortRepository.LoadEscort();
}
}
With the modified code you can now unit test the service class, plus the responsiblity of obtainig the respository is now not the concern of the service due to the fact that we are now injecting it into the class via the constructor - dependency injection.
If you were being pragmatic you might not want a service layer at all as its not really giving you anything. However if you wanted to cache the results from the repository or indeed perform some other bit of business logic then the service layer would start becoming useful.
I hope that was of some use. let me know if you have any more questions.
Cheers Scott