Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autofac configuration validation

Does Autofac have an equivalent to StructureMap's AssertConfigurationIsValid method? Or does configuration validation occur when creating the container?

I believe the AssertConfigurationIsValid method checks that the container can create all the configured services. Obviously it can't pick up more subtle configuration mistakes - related to scope, for instance - but it would be nice to know that we are doing as much as we can to prevent issues that could crop up at runtime.

like image 344
JulianM Avatar asked May 06 '10 08:05

JulianM


1 Answers

I don't think Autofac have validation, and an exception is thrown at runtime if a service cannot be resolved. It would probably be useful but I always tend to write unit tests that validates that my container, or rather my modules, contain those services I expect it to have. Unit testing more than makes up for the lack of container validation.

These tests usually follow the pattern of

  1. Create a container with the module under test
  2. For each required service, test container.IsRegistered
  3. Whenever possible, test container.Resolve
like image 89
Peter Lillevold Avatar answered Oct 21 '22 21:10

Peter Lillevold