开发者

Why won't StructureMap spawn an instance of my tax strategy class?

StructureMap works great for all my other repository classes, but fails to provide an instance of my sim开发者_如何学JAVAple tax strategy class. The error is thrown whether I request an instance in a constructor parameter or explicitly request it:

StructureMap Exception Code:  202
No Default Instance defined for PluginFamily System.Decimal, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Not sture why the error is planted on System.Decimal, but in my Bootstrapper Registry I have:

For<ITaxStrategy>().Use<ValueAddedTax>();

where ITaxStrategy is the following simple interface:

public interface ITaxStrategy
{
    decimal CalculateTax(decimal amount);
}

and ValueAddedTax is implemented as:

public class ValueAddedTax : ITaxStrategy
{
    private decimal _taxRate = 1.14M;

    public ValueAddedTax(decimal taxRate)
    {
        _taxRate = taxRate;
    }

    public decimal CalculateTax(decimal amount)
    {
        return amount * _taxRate; // this be pulled from the database.
    }
}

I even upgraded to the 2.6.1 StructureMap assembly, but the error persists. What am I doing wrong?


Ah! I wasn't providing the necessary decimal constructor argument!

Solved with:

For<ITaxStrategy>().Use<ValueAddedTax>().Ctor<decimal>().Is(1.14M);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜