Container.Configure<> constraint

Feb 19, 2008 at 5:09 AM
As discussed before (by that I mean during the workshop but the attendees at figured that out already ;) ),

I wish the Configure method only had a constraint on a IUnityContainerExtension interface instead of IUnityContainerConfigurator.

Having to define an interface for every extension just to gain access to the guts of the extension seems a bit overkill for me. However, by having the constraing loosen, I still believe it is a great idea to support that Configure<T> looks through all extensions to find the one that is assignable to T. I just wish the constraint wasn't as strict.
Feb 21, 2008 at 7:32 PM
I just wrote this passing test:

public void CanLookupExtensionByClassName()
MockContainerExtension extension = new MockContainerExtension();
IUnityContainer container = new UnityContainer();

MockContainerExtension result = container.Configure<MockContainerExtension>();

Assert.AreSame(extension, result);

Note that I looked up the extension by it's type directly, not by any interface. This works because the UnityContainerExtension base class implements the IUnityContainerConfigurator interface already. So I think you're automatically getting what you're asking for. Or am I misunderstanding your request?
Feb 21, 2008 at 7:52 PM
My mistake. I believe we just didn't realize it during the workshop.

Do you think it would make sense to rename the interface to:

public interface IUnityContainerExtension
  IUnityContainer Container { get; }

It could then be reused for other scenarios.

And maybe methods part of UnityContainerExtension base class (InitializeExtension, Remove) could also be promoted to the interface so that container.AddExtension could have a constraint on the interface instead of an abstract base class as requested in my other discussion.