StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

前端 未结 8 1238
-上瘾入骨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:39

    I was getting the same error message, but for a different reason. I had a class Foo that defined two constructors like so:

    public class Foo : IFoo
    {
        private Bar _bar;
    
        public Foo()
        {
           _bar = new Bar();
        }
    
        public Foo(Bar bar)
        {
            _bar = bar;
        }
    }
    

    and my StructureMap configuration was like so:

    For.Use();
    

    I kept getting an error message like

    202 No Default Instance defined for Bar

    The problem was that StructureMap was trying to construct a Foo using the constructor that takes a parameter, instead of using the parameterless default constructor. I solved it using the answer in How to define a default constructor by code using StructureMap? like so:

    For.Use(() => new Foo());
    

提交回复
热议问题