I have an abstract class:
public abstract class Validator<T> : IValidator
and a couple of classes that implement this class for specific purposes, e.g.
public sealed class NewsValidator : Validator<News>
Now using Ninject i want to do Dependency Injection like the following (this particular code is NOT working):
Bind<Validator<News>>().To<NewsValidator>();
Bind(typeof(Validator<>)).To(typeof(NullValidator<>));
So what I want to achieve is that
Validator<News>
Should be bound to the Class "NewsValidator", but if any other not-bound version of this class is requested, say
Validator<Article>
Validator<SomethingElse>
that should be bound to a default Class (NullValidator). Using the code used above throws an Exception, though, because it binds the Validator < News > both to the NewsValidator as well as to the NullValidator.
How could I implement this? Particular types of the generic class should be bound to individual classes. All other types of the generic class that were not explicitly bound should be bound to a default class.
Would be really glad about a couple of suggestions! Thanks!