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);
精彩评论