如何将LinFu运行时错误转换为编译时错误

时间:2013-06-05 04:37:22

标签: c# .net runtime-error ioc-container linfu

我对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来实例化对象时,我的代码仍会编译很好但是会发生运行时错误。

感谢。

如何修改我的代码以便收到编译时错误,我可以快速轻松地修复它们。

0 个答案:

没有答案