我对 IoC 的接触很少,并且正在使用 LinFu。我遇到的主要问题是直到运行时才发现错误。我更喜欢处理编译时错误。
例如,如果我使用以下代码创建一个对象:
return ServiceContainer.GetService(typeof(IPurchaseOrder), tPO.IntPOId,
tPO.CustPONumber, custFac, tPO.FulfilledDate) as IPurchaseOrder;
我为实现此接口而创建的对象是:
[Implements(typeof(IPurchaseOrder), LifecycleType.OncePerRequest)]
public class PurchaseOrderImpl : IPurchaseOrder
{
public PurchaseOrderImpl(int intPOID, string customerPONumber, ICustomerFacility custFacility, DateTime? fulFilledDate )
{
IntPOID = intPOID;
CustomerPONumber = customerPONumber;
CustomerFacility = custFacility;
FulFilledDate = fulFilledDate;
}
..........
假设我现在想向构造函数添加另一个参数:
[Implements(typeof(IPurchaseOrder), LifecycleType.OncePerRequest)]
public class PurchaseOrderImpl : IPurchaseOrder
{
public PurchaseOrderImpl(int intPOID, string customerPONumber, ICustomerFacility custFacility, DateTime? fulFilledDate, double commision )
{
IntPOID = intPOID;
CustomerPONumber = customerPONumber;
CustomerFacility = custFacility;
FulFilledDate = fulFilledDate;
Commision = commission;
}
..........
如果我这样做了,那么我的代码仍然可以很好地编译,但是当我调用 GetService 来实例化对象时,会发生运行时错误。
谢谢。
如何修改我的代码以便接收编译时错误并且我可以快速轻松地修复它们。