This will likely (hopefully?) be an “amateur hour” type question. 🙂
I’m new to interfaces, etc. and doing things correctly, but I have an MVC 3 project that references a C# library project.
In the C# library project, I have the following code:
public interface IRepositoryAddable<T>
{
void Add(T entity);
}
I repeat this sort of code for other types of repository so that I can make things easier and standard across all my repositories.
For example, I have a repository for anything of type “ISkill”:
public interface ISkillRepository : IRepositoryAddable<ISkill>, IRepositoryDeleteable<ISkill>, IRepositoryDeleteableByID<ISkill, int>, IRepositoryGettableByID<ISkill, int>, IRepositoryListable<ISkill>, IRepositorySavable<ISkill>
{ }
Then, in my actual repository, I have:
public class SkillRepository : ISkillRepository
{
public void Add(Skill skillToAdd)
{
return;
}
}
As far as I’m aware, this should suffice to implement the ISkillRepositoryListable interface. However, I receive the following error:
Error 5 ‘DakotaSkills.MVC.Models.Repository.SkillRepository’
does not implement interface member
‘DakotaSkills.Lib.Interfaces.Repository.IRepositoryAddable.Add(DakotaSkills.Lib.Interfaces.ISkill)’ C:\Users\Sean\Projects\Web\DakotaSkills\src\DakotaSkills.MVC\Models\Repository\SkillRepository.cs 11 18 DakotaSkills.MVC
Other interface methods for the repository have shown as being implemented fine and I’m not quite sure what I’m doing wrong. For the record, my “Skill” type implements “ISkill” and I receive no error on its implementation.
Help?
Thanks!
Your Add would not accept some other class that also implemented ISkill. You need to take an ISkill, not just a Skill. That also suggests that your implementation of Add, should it ever do anything, should do so through ISkill only and not by calling other Skill methods you may know about.