I have a base class and a number of other classes inheriting from this:
(Please excuse the analogue of the used animal)
public abstract class Animal {}
public class Dog: Animal {}
open class Cat: Animal {}
Then I have a class that has a dependency on IEnumerable<Animal>
public class AnimalFeeder { private readonly IEnumerable<Animal> _animals; public AnimalFeeder(IEnumerable<Animal> animals ) { _animals = animals; } }
If I manually do something like this:
var animals = typeof(Animal).Assembly.GetTypes() .Where(x => x.IsSubclassOf(typeof(Animal))) .ToList();
Then I see that this returns Dog and Cat
However, when I try to connect my Autofac, for example:
builder.RegisterAssemblyTypes(typeof(Animal).Assembly) .Where(t => t.IsSubclassOf(typeof(Animal))); builder.RegisterType<AnimalFeeder>();
When AnimalFeeder is created, Animal is not passed in the constructor.
Did I miss something?
source share