When Chill 1.0 wanted to know which container (for example the Chill.AutofacNSubstitute container) it needed to use, it would scan your loaded assemblies for types that implemented the IChillContainer. While this worked, it also posed several issues.
For one, you couldn’t use different types of chill containers. For example, if you wanted to have tests with several containers that do automocking, some without automocking, some with very specific registrations set up), you couldn’t do that.
The other issue had to do with portable class libraries. I wanted to make Chill a portable class library. For example if you wanted to test Xamarin IOS classes (without turning them into PCL’s), then you can only reference PCL’s or Xamarin IOS dll’s from your test project.
But, to turn Chill into a PCL, I had to change the way it did assembly scanning. PCL’s have quite a lot of restrictions with regards to assembly scanning.
However, I think the end result is quite elegant.
Basically, if you install a specific container, Chill will add an assembly level attribute, in a file called DefaultChillContainer:
// This attribute defines which container will be used by default for this assembly
public class When_configuring_container_with_module_and_objectmother : GivenWhenThen
Under the covers, Chill will wrap the container you specify in a AutoMotherDecorator (more on AutoMothers in a later blog post). If you don’t want this, then you can specify a custom ChillContainerInitializer:
As always, keep it cool, keep it Chill!