This project has moved and is read-only. For the latest updates, please go here.

SimpleIoc auto register

Jun 18, 2011 at 5:30 AM


I created a fork where I changed SimpleIoc to auto register unregistered types. That test shows what I am talking about:

        public void TestAutoRegister() {
            SimpleIoc.Default.Register<ITestClass, TestClass>();
            var instance1 = SimpleIoc.Default.GetInstance<TestClass3>(); //TestClass3 has ITestClass as a constructor parameter
            Assert.IsInstanceOfType(instance1.SavedProperty, typeof(TestClass));

If the type can be created, it gets registered and it's created. It it's an abstract class or an interface, you get the activation exception.

I found it very useful to avoid having to register concrete types (like all my viewmodels).

I also fixed the unit tests this new behavior broke.

If you like the idea, I'm more than happy to send you a pull request.

Cheers and thank you for this amazing framework,

André Carlucci

Jun 30, 2011 at 10:18 AM

That sounds nice, thanks for sharing!