Question

My controllers use services rather than repositories directly. The services are placed in the ApplicationServices project:

public XYZService
        (
            IBlaRepository BlaRepository,
            IBla1Repository Bla1Repository
        )
        {
            Check.Require(BlaRepository != null, "BlaRepository may not be null");
            this.BlaRepository = BlaRepository;
        ....

This works fine.

The repositories are implemented as follows:

public interface IBlaRepository : IRepository<Bla> (placed in Core/DataInterfaces)

public class BlaRepository : Repository<Bla>, IBlaRepository (placed in Data)

Sometimes I can just use the ‘plain’ sharp architecture repository. Is there a way to pass them into the above service? Do I have to register them somewhere?

To clarify this – the contructor of the service looks like this:

public XYZService
        (
            Repository<UUU> UUURepository

...

Hope this makes sense.

Thanks!

chris

Was it helpful?

Solution

Chris, all you would need to do is refer to your repository as such:

    private readonly IRepository<Bla> _blaRepository; 

    public BlaService(IRepository<Bla> blaRepository) 
    { 
         _blaRepository = blaRepository; 
    }

This will allow Windsor to inject the repository into your controller with nothing else needed by you.

Alec

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top