Jon
Jon

Reputation: 40062

Can a IOC Container replace CreateInstance reflection code?

I have a similar setup shown in this question and was wondering if I could replace all my code that uses reflection to find plugins of a certain type and then does a CreateInstance on it with a IOC Container that does something like:

builder.RegisterAssemblyTypes(typeof(MyType).Assembly)

Upvotes: 3

Views: 457

Answers (1)

Mark Seemann
Mark Seemann

Reputation: 233307

Yes, you could do something like this:

builder.RegisterAssemblyTypes(typeof(MyType).Assembly).AsImplementedInterfaces();

Upvotes: 1

Related Questions