C
C#2w ago
Jacko

Get information about DI container:

So I’ve read that it’s a bad idea to pass a DI container into a class and use .get() because it’s a service locator pattern which isn’t recommended. I’m trying to make a cli with a plugin system and as part of that I want to have a debug command that returns all the registered plugins from the di container. Is there a best practice way to do this using Autofac ? I want to have a class like ContainerService which has some methods to get registered services, find their file locations etc.
3 Replies
Sehra
Sehra2w ago
if all the plugins implement for example IPlugin, you can ask autofac to resolve IEnumerable<IPlugin> to get them all, or you can also register them with metadata to later use
Jacko
JackoOP2w ago
Oh that’s actually a lot easier than I expected haha I’ll give that a try thank you !
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?