I’m looking into using a IOC container but I’m working with legacy code and there are loads of CreateInstance‘s everywhere and then things done with that class.
Is there a way I can get a IOC container to return a list of classes it has instantiated so the methods currently in use can continue doing their thing just without the CreateInstance
For example Autofac will scan an assembly/set of assemblies with code similar to the below, I was just wondering if it can return a List<T> of the classes it has created.
var dataAccess = Assembly.GetExecutingAssembly();
builder.RegisterAssemblyTypes(dataAccess)
.Where(t => t.Name.EndsWith("Repository"))
.AsImplementedInterfaces();
UPDATE: I’m just deciding on which IOC to use but need the above functionality to tell me at what classes have been instantiated.
You mean something like
The above syntax works as long as all classes that derive
YourClassTypehas been been registered as it._container.Resolve<IEnumerable<T>>()tells autofac to resolve all classes that implementT.