Container self registration

Jul 6, 2012 at 2:23 AM

I've noticed a difference between these 2 scenarios:

var container = new Container();

var container = new Container(new ContainerOptions { AllowOverridingRegistrations = false });

In the first case the container registers itself, in the second it does not.

Personally I'd prefer the container to always be registered, but either way I'd prefer it to be consistent.

Jul 6, 2012 at 7:02 AM

This is a known bug in current 1.4.2 release. A fix has already been checked in and it the next release of the core library will contain that fix. I expect it to be released in a couple of weeks. In the meantime, you can use the following workaround for this:

catch (InvalidOperationException) { }

Jul 7, 2012 at 11:14 PM

What will the default behaviour be when the new release comes out?

Empty try catch blocks are one of my most hated code smells and I'd prefer to avoid them.

Jul 8, 2012 at 10:18 AM

The next version will always register the container. You will never have to register the container with that version and therefore don't need this workaround when working with that version. In fact, with the current version, you don't need empty catch at all, but using this exact code snippet, allows your application to keep working, when you migrate to the new version, since registering the container manually will always fail in the next version (since it's already registered).

The most painful thing about this bug is that fixing it, is a breaking change :-(

Jul 18, 2012 at 4:41 PM

Version 1.5.0 has just been released. This bug has been fixed in this release.

Marked as answer by dot_NET_Junkie on 11/4/2013 at 1:58 AM