StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

前端 未结 8 1220
-上瘾入骨i
-上瘾入骨i 2020-12-20 11:05

I am new to StructureMap. I have downloaded and am using version 2.6.1.0. I keep getting the below error:

StructureMap Exception Code: 202 No Def

8条回答
  •  庸人自扰
    2020-12-20 11:48

    Mine was because I had accidentally referenced the concrete type in the constructor of another class rather than the interface

    eg in structuremap i had

    x.For().Use();
    x.For().Use();
    

    and constructor for Foo looked like this

    public class Foo : IFoo {
        public Foo(Bar bar) {...}
    }
    

    when it should have looked like this as SM couldn't just create an instance of Bar, it only knows how to make an IBar:

    public class Foo : IFoo {
        public Foo(IBar bar) {...}
    }
    

    It also meant that my exception referenced the concrete type instead of the interface but I missed that initially

提交回复
热议问题