IOC and Plugins

I have all my services split out into separate IPlugin, each which registers a number of types in the IOC - as usual.
Each service may register one or more types in the IOC that implement a generic interface ISomething<T>.

In the AppHost.cs where these plugins are used, I need to register a special service that requires an array of all the instances of all the types that are registered in the IOC that implement ISomething<T>.

Here is the registration factory of the special service:

public override void Configure(Container container)
    container.AddSingleton<ISpecialService>(x => new SpecialService(somethings));

where somethings is an array of resolved instances of ISomething<T>

What I don’t know, is how to provide calculate or provide the variable somethings (above) so that the registered ISomething<T> instances are not resolved until all the plugins are fully loaded and registered.

Is there something in the framework that can help me here?

There’s nothing in the IOC to prevent anyone from resolving registered dependencies.

But there are plugin life-cycle events your plugins can implement, e.g. they can implement IPreInitPlugin to get called before any plugins are registered or implement IPostInitPlugin to get called after all plugins are registered.

Finally your plugins can also register a callback handler in IAppHost.AfterInitCallbacks which is the last user-registered callback that gets invoked before the AppHost has finished starting.


My issue is not really registering the instances of the ISomething<T> in the IOC. That is already done in my plugins.

The problem is finding all those instances from the IOC when my ISpecialService needs an array of those instances in its factory ctor.

I dont see any methods in the IOC to either scan all the registered types in the IOC, or resolve multiple instances of the same generic interface (ISomething<T>) that I can use to build the array of instances.

There’s no functionality to scan registered deps, you’d need to maintain a list of registrations yourself.