I am not sure how to use StructureMap to scan for all repositories in a particular namespace. Most repositories take the form:
namespace CPOP.Infrastructure.Repositories
{
public class PatientRepository : LinqRepository<Patient>, IPatientRepository
{
}
}
namespace CPOP.Infrastructure.Repositories
{
public class LinqRepository<T> : Repository<T>, ILinqRepository<T>
{
}
}
namespace CPOP.Domain.Contracts.Repositories
{
public interface IPatientRepository : ILinqRepository<Patient>
{
}
}
I tried:
x.Scan(scanner =>
{
scanner.Assembly(Assembly.GetExecutingAssembly());
scanner.ConnectImplementationsToTypesClosing(typeof(ILinqRepository<>));
})
But, it only picks up the LinqRepository
class. What's the best way to pick up the various repositories I'll be dumping in there?
And, as per Joshua's reuest, here's an example of use:
namespace CPOP.ApplicationServices
{
public class PatientTasks : IPatientTasks
{
private readonly IPatientRepository _patientRepository;
public PatientTasks(IPatientRepository patientRepository)
{
_patientRepository = patientRepository;
}
public Patient GetPatientById(int patientId)
{
int userId; // get userId from authentication mechanism
return _patientRepository.FindOne(new PatientByIdSpecification(patientId));
}
public IEnumerable<Patient> GetAll()
{
int userId; // get userId from authentication mechanism
return _patientRepository.FindAll();
}
}
}