0

I have had minimal exposure to IoC and am using LinFu. The main problem I am having is that errors are not being picked up until run-time. I much prefer to deal with compile time errors.

For example, if I create an object using the following code:

            return ServiceContainer.GetService(typeof(IPurchaseOrder), tPO.IntPOId,
                 tPO.CustPONumber, custFac, tPO.FulfilledDate) as IPurchaseOrder;

The object I have created to implement this interface is:

[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;
    }

     ..........

Let's say I now want to add another parameter to the constructor:

[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;
    } 

     ..........

If I do then then my code still compiles fine BUT when I call GetService to instantiate the object a run time error will occur.

Thanks.

How can I modify my code so that compile time errors are received and I can fix them quickly and easily.

  • I don't see a "compile time" solution for your problem. IoC container configuration/misconfiguration is not usually something that can be exposed at compile time. A set of unit tests would definitely expose it... – Dusty Lau Jul 08 '13 at 16:54
  • Thanks for your response. I don't have any unit testing. Perhaps I need to start doing that. I just thought I must have been doing something 'wrong' as not having something flag up when the application is built seems like a step backwards. – user2454186 Jul 26 '13 at 00:31

0 Answers0