I personally would avoid services using other services because sooner or later you'll get a circular reference. Having the services not depend on each other also makes for looser coupling and ease of testability. So i would go for method 1.
The problem with this approach comes when you want to reuse functionality between services. In your case you can just defer calls to the respective repository, but in more complex cases you may need to add a domain object that contain common business logic that can be re-used in the different services. For example, if you had to have a complex isFooExisted
method in both services, you might do something like this (note that I have changed your code to use dependency injection to make your code more testable):
public class BarService
{
private FooEntity fooEntity;
public BarService(IFooRepository repository)
{
this.fooEntity = new FooEntity(repository);
}
public IEnumerable<Foo> getFoo(int FooID)
{
return fooEntity.getFoo(FooID);
}
}
public class FooService
{
private FooEntity fooEntity;
public FooService(IFooRepository repository)
{
this.fooEntity = new FooEntity(repository);
}
public IEnumerable<Foo> getFoo(int FooID)
{
return fooEntity.getFoo(FooID);
}
}
public class FooEntity
{
private IFooRepository repository;
public FooEntity(IFooRepository repository)
{
this.repository = repository;
}
public bool isFooExisted(int FooID)
{
/** Complex business logix **/
}
}
And for the simple case I'd just use the same repository directly and not have the domain object:
public class BarService
{
private IFooRepository repository;
public BarService(IFooRepository repository)
{
this.repository = repository;
}
...
}
public class FooService
{
private IFooRepository repository;
public FooService(IFooRepository repository)
{
this.repository = repository;
}
...
}
Hope this helps.