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

C# 如何将LinFu运行时错误转换为编译时错误,c#,.net,runtime-error,ioc-container,linfu,C#,.net,Runtime Error,Ioc Container,Linfu,我对国际奥委会的接触很少,我使用的是林孚。我遇到的主要问题是直到运行时才会发现错误。我更喜欢处理编译时错误 例如,如果使用以下代码创建对象: return ServiceContainer.GetService(typeof(IPurchaseOrder), tPO.IntPOId, tPO.CustPONumber, custFac, tPO.FulfilledDate) as IPurchaseOrder; 我为实现此接口而创建的对

我对国际奥委会的接触很少,我使用的是林孚。我遇到的主要问题是直到运行时才会发现错误。我更喜欢处理编译时错误

例如,如果使用以下代码创建对象:

            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来实例化对象时,会出现运行时错误

谢谢


如何修改代码以接收编译时错误,并快速轻松地修复它们。

我看不到解决您问题的“编译时”解决方案。IoC容器配置/错误配置通常不会在编译时公开。一组单元测试肯定会暴露它…感谢您的回复。我没有任何单元测试。也许我需要开始这样做。我只是想我一定是做错了什么,因为在构建应用程序时没有进行标记似乎是一种倒退。