This is the interfaces/class structure I have now:
BaseContentObject abstract class
public abstract class BaseContentObject : IEquatable<BaseContentObject>
{
...
}
Page concrete class
public class Page : BaseContentObject
{
...
}
Repository interface
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; }
}
Common interface implementation (for all content classes that inherit BaseContentObject class)
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);
}
...
}
Content specific repository
public class XmlPagesRepository : XmlRepository<Page> { }
Ninject rule in global.asax.cs
Bind<IContentRepository<Page>>().To<XmlPagesRepository>();
that gives the following compile time error:
*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>'.*
I've spent quite some time figuring out my classes and interfaces structure to support my business needs. Now I don't know how to get past that Ninject error.
I want to use this structure in ASP.NET MVC controllers like this:
public IContentRepository<Page> ContentRepository { get; private set; }
public PageController(IContentRepository<Page> repository)
{
ContentRepository = repository;
}