Creating a log of root types that have not been registered.

Coordinator
Sep 3, 2014 at 2:49 AM
Simple Injector can generate an implicit run-time registration for any requested concrete type (i.e. it can create a type even if that type has not been explicitly registered with the Container), but to be able to diagnose and verify the Container's configuration it is important to explicitly register all root types.

What do you think of adding a hook or an event to enable logging of implicit registrations?
Coordinator
Sep 3, 2014 at 8:06 AM
That's an interesting request, but there's a bit a paradox in the request. Unregistered root objects (obviously) can't be spotted during verification, since they are registered at a later point in time. This means that when you want to see those registrations, you need to have access to the container during runtime or when debugging. Since this would normally not be the case you will have to do extra work to access the container. If you're doing this, that means that you are actively searching for unregistered roots. But if you're actively searching for this, you are already aware of the problem and probably know how to register your root types up front. This feature is especially useful for developers who are unaware of the issue, but the container will never be able to help them with that, since they won't (be able to) access the container at runtime. In that sense the the feature will only help the developers who are already aware of the issue and don't need to be notified by this.

Nonetheless, it is currently possible to query the container to get a list of 'unregistered root types' as follows:
var container = new Container();

// [Do registrations here.]

// Verify and store the list of known registrations (important to verify)
container.Verify();
var knownRegistrations = container.GetCurrentRegistrations();

// [During application use, resolve your root types]

// Request the list of unregistered root types as follows:
var unregisteredRoots = container.GetRootRegistrations().Except(knownRegistrations).ToArray();
Coordinator
Sep 6, 2014 at 3:01 AM
Edited Sep 6, 2014 at 3:02 AM
I think the documentation needs to stop making a big deal about implicit registrations and should more than likely advise against it.

If the developer does not register any controllers in their application then the call to Verify will not do much of the checking we are suggesting it does.
Coordinator
Sep 6, 2014 at 7:52 AM
Edited Sep 28, 2014 at 11:17 AM
I think in most cases the library and docs already guide developers into that direction. For instance:
  • The diagnostics contain a warning about unregistered (non-root) type.
  • The integration packages container extension methods for registering root types such as RegisterMvcControllers.
  • The quick start NuGet packages inject code into the application that calls such extension method.
  • The integration documentation describes the use of those methods.
  • The How to Verify the container section explicitly states "Register all root objects explicitly if possible".
But we might still do a better job in this. Can you point at parts of the documentation that promote (or lack to warn about) implicit registrations?