This project is read-only.

Container.Verify() tries to instantiate all components?

Jun 28, 2013 at 5:34 PM
I tried using the Container.Verify() method after registration, and it seemed to be trying to create instances of all registered components, and blew up on me because some things were not intended to be instantiated without first having things like DB connection information set up.

Can you confirm this is what it does? Wouldn't it be less invasive to build a graph of dependencies and then insure that every possible instantiation can be resolved, based on constructor parameters, etc.?

Thanks.
Jun 29, 2013 at 7:16 PM
This is exactly what Container.Verify() does. The only way it can ensure that an object graph can be resolved is by creating it.

It's not always possible to call Verify() in every application, but you should strive to having a verifiable configuration.

But besides trying to have a verifiable configuration, you should be able to compose object graphs with confidence and an injection constructor should do no more than receiving the dependencies. You should prevent opening database connections in injection constructors. This is logic that should not be executed at this stage. And this is not a DI pattern per see; even the .NET framework design guidelines have this as a design rule, and you'll see pattern in things like ADO.NET's SqlConnection, LINQ to SQL's DataContext, and Entity Framework's ObjectContext and DbContext classes: they all do not open an underlying connection to the database during construction. SqlConnection has an explicit Open method, and the OR/M tools open a connection implicitly for you lazily.
Marked as answer by dot_NET_Junkie on 3/2/2014 at 10:48 AM