My application sould check its settings at startup and only then start.
I’m trying to figure out how to deal with it using DI container. On one hand I don’t want to put this self-check into composition root. On the other hand if this check fails then we don’t need to register all types with DI container and may simply exit.
So I think of some 2-phase DI. At the first stage only types required during self-check are registered and at the second stage the whole set of types is registered and application object resolved and started. But I don’t see how it can be done.
How would you deal with such a situation? I’m using Autofac.
Thanks.
For a two phase approach, you could initially build the container with the core application components. You would then resolve these and run your checks. If the checks pass, you could then update the container with the reflected plugins by using the
Updatecontainer method.However, do you need DI for your settings validation types? Why not just use them directly before you build the container?