So, you create a layout ITreatmentRepositoryby customizing some kind of behavior and inject it into your class TreatmentBusiness. So far, so good.
But then in your method AddTreatmentsyou create a new one TreatmentRepositoryinstead of using the one that is introduced through the constructor.
, :
public class TreatmentBusiness
{
private readonly ITreatmentRepository repository;
public TreatmentBusiness(ITreatmentRepository repository)
{
this.repository = repository;
}
...
}
:
public void AddTreatments(TreatmentView model)
{
using (var treatment= this.repository)
{
var treat = new PhysiqueData.ModelClasses.Treatment();
{
treat.treatmentID = model.treatmentID;
treat.treatmentCost = model.treatmentCost;
treat.treatmentDuration = model.treatmentDuration;
treat.treatmentName = model.treatmentName;
}
treatment.Insert(treat);
}
}
repository, .
Jimmy_keen, , factory.
factory, factory, , :
public class TreatmentBusiness
{
private readonly ITreatmentRepositoryFactory repositoryFactory;
public TreatmentBusiness(ITreatmentRepositoryFactory repositoryFactory)
{
this.repositoryFactory = repositoryFactory;
}
...
}
:
public void AddTreatments(TreatmentView model)
{
using (var treatment= this.repositoryFactory.Make())
, , (Func<>) , TreatmentRepository.
:
public class TreatmentBusiness
{
private readonly Func<TreatmentRepository> getTreatmentRepository;
public TreatmentBusiness(Func<TreatmentRepository> getTreatmentRepository)
{
this.getTreatmentRepository = getTreatmentRepository;
}
....
}
:
public void AddTreatments(string model)
{
using (var treatment = this.getTreatmentRepository())
{
...
}
}
, , , , , Business:
var treatmentBusiness = new TreatmentBusiness(() => new TreatmentRepository());
IoC/ DI .