I have read lots of Autofac docs/wikis which indicate I can get a list of all the registered types by doing something as simple as shown below:
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.AssignableTo<IPersistedModel>();
var container = builder.Build();
var allTypes = container.Resolve<IEnumerable<IPersistedModel>>();
The problem is allTypes comes up empty.
In the debugger I can see inside the container and there are 7 matching types and even an array of IPersistedModel… but they do not get returned on Resolve().
What am I missing?
You need to register the types as the interface, either using
.As<IPersistedModel>()or for all its interfaces using.AsImplementedInterfaces():