I'm getting the dreaded "No default Instance is registered and cannot be automatically determined for type" even though I have set a registry for the default conventions.

To debug I am trying the WhatDoIHave and Asset... methods but these no longer exist on ObjectFactory. Am I missing something or have these been removed in the latest version?

有帮助吗?

解决方案

Jeremy Miller explains new improved error reporting in SM3 3.0 here.

"WhatDoIHave" remains in SM 3: (taken from the above blog entry)

   [Test]
    public void what_do_I_have()
    {
        var container = new Container(x => {
            x.For<IDevice>().AddInstances(o => {
                o.Type<ADevice>().Named("A");
                o.Type<BDevice>().Named("B").LifecycleIs<ThreadLocalStorageLifecycle>();
                o.Type<CDevice>().Named("C").Singleton();
            });

            x.For<IDevice>().UseIfNone<DefaultDevice>();
        });

        Debug.WriteLine(container.WhatDoIHave());

        Debug.WriteLine(container.WhatDoIHave(pluginType:typeof(IDevice)));
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top