와 저장소 패턴이 지금 가지고있는 인터페이스/클래스 구조입니다 :Ninject에와 인터페이스
BaseContentObject 추상 클래스
public abstract class BaseContentObject : IEquatable<BaseContentObject>
{
...
}
페이지 구상 클래스
public class Page : BaseContentObject
{
...
}
저장소 인터페이스
public interface IContentRepository<T>
{
// common methods for all content types
void Insert(T o);
void Update(T o);
void Delete(string slug);
void Delete(ContentType contentType, string slug);
IEnumerable<T> GetInstances();
T GetInstance(ContentType contentType, string slug);
T GetInstance(string contentType, string slug);
T GetInstance(string slug);
IEnumerable<string> GetSlugsForContentType(int limit = 0, string query = "");
ContentList GetContentItems();
bool IsUniqueSlug(string slug);
string ObjectPersistanceFolder { get; set; }
}
공통 인터페이스 구현
public class XmlRepository<T> : IContentRepository<BaseContentObject>
{
public string ObjectPersistanceFolder { get; set; }
public XmlRepository()
{
ObjectPersistanceFolder = Path.Combine(XmlProvider.DataStorePhysicalPath, typeof(T).Name);
if (!Directory.Exists(ObjectPersistanceFolder))
Directory.CreateDirectory(ObjectPersistanceFolder);
}
...
}
내용 특정 저장소 (BaseContentObject 클래스를 상속 모든 콘텐츠 클래스)
는public class XmlPagesRepository : XmlRepository<Page> { }
global.asax.cs에서
Ninject에 규칙
Bind<IContentRepository<Page>>().To<XmlPagesRepository>();
다음을 제공하는 컴파일 시간 오류 :
*The type 'Namespace.XmlPagesRepository' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax<T>.To<TImplementation>()'. There is no implicit reference conversion from 'Namespace.XmlPagesRepository' to 'Namespace.IContentRepository<Namespace.Page>'.*
저는 비즈니스 요구를 지원하기 위해 클래스와 인터페이스 구조를 파악하는 데 많은 시간을 투자했습니다. 이제 나는 그 Ninject 오류를 피하는 법을 모른다.
나는 다음과 같은 ASP.NET MVC 컨트롤러에서이 구조를 사용하려면 :
public IContentRepository<Page> ContentRepository { get; private set; }
public PageController(IContentRepository<Page> repository)
{
ContentRepository = repository;
}
wouldnt가 완전히 당신이 뭘 하려는지 이해없이, 이것은 내가 저장소를 설계 할 방법입니다 컴파일 시간 오류를주는 상처 - 그것은이 문제를 치고 큰 문제로 간주하지 않고 그것을 해결 한 사람들에게 이것을 열어 놓을 것입니다. –