I have an abstract class:
public abstract class Validator<T> : IValidator
and several classes that implement this class for specific purposes, for example
public sealed class NewsValidator : Validator<News>
Now, using Ninject, I want to make Injection Dependency as follows (this specific code DOES NOT work):
Bind<Validator<News>>().To<NewsValidator>(); Bind(typeof(Validator<>)).To(typeof(NullValidator<>));
So I want to achieve that
Validator<News>
Must be bound to the NewsValidator class, but if any other unrelated version of this class is requested, say
Validator<Article> Validator<SomethingElse>
which should be bound to the default class (NullValidator). The use of the code used above raises an exception, though, since it binds the Validator <News> to both NewsValidator and NullValidator.
How could I implement this? Separate types of a generic class must be bound to separate classes. All other types of the general class that were not explicitly bound must be bound to the default class.
Would be really happy with some suggestions! Thanks!
source share