Exception that a constructor parameter does not exist when it

I am trying to inject two interface-based Unity objects into a class constructor.

In the testing module, I get the following error:

Message:
Test method TestProject.TFStests.Check_Interface_CheckOut_Method throws an exception: System.InvalidOperationException: type Adp.Tools.VersionControl.TfsVersionControl.TfsVcPromotionManager does not have a constructor that accepts parameters (TfsVcWerckout).

The following code is my Unity class, it is used to register and resolve an object TfsVCPromotionManager:

public class UnityClass
{
    public static ITfsVcPromotionManager returnNewPromotionManager(
       VersionControlServer tfServer)
    {
        var container = new UnityContainer();

        ITfsVcQaCheckinWorker test1 = CreateUnityCheckInWorker();
        ITfsVcQaCheckoutWorker test2 = CreateUnityCheckOutWorker(tfServer);

        container.RegisterType<ITfsVcPromotionManager, TfsVcPromotionManager>(
            new InjectionConstructor(test2), new InjectionConstructor(test1));
        return container.Resolve<TfsVcPromotionManager>();
    }

    private static ITfsVcQaCheckinWorker CreateUnityCheckInWorker()
    {
        var container = new UnityContainer();

        container.RegisterType<ITfsVcQaCheckinWorker, ITfsVcQaCheckinWorker>();
        return container.Resolve<TfsVcQaCheckinWorker>();
    }

    private static ITfsVcQaCheckoutWorker CreateUnityCheckOutWorker(
        VersionControlServer passedServer)
    {
        var container = new UnityContainer();

        container.RegisterType<ITfsVcQaCheckoutWorker, TfsVcQaCheckoutWorker>(
            new InjectionConstructor(passedServer));
        return container.Resolve<TfsVcQaCheckoutWorker>();
    }
}

This is constrcutor from the class TfsVCPromotionManager. note that it explicitly accepts an instance based on ITfsVcQaCheckoutworkerand interfaces ITfsVcCheckinWorker.

 private ITfsVcQaCheckoutWorker _checkOutWorker;

    private ITfsVcQaCheckinWorker _checkInWorker;

    public TfsVcPromotionManager(ITfsVcQaCheckoutWorker checkOutWorker,
                                 ITfsVcQaCheckinWorker checkInWorker)
    {
        if (checkOutWorker == null || checkInWorker == null)
        {
            throw new NullReferenceException();
        }

        _checkOutWorker = checkOutWorker;
        _checkInWorker = checkInWorker;
    }

- , .

+4
2

, ", (TfsVcQaCheckoutWorker)", . , . Unity, , :

container.RegisterType<ITfsVcPromotionManager, TfsVcPromotionManager>(
    new InjectionConstructor(test2),
    new InjectionConstructor(test1))

:

container.RegisterType<ITfsVcPromotionManager, TfsVcPromotionManager>(
    new InjectionConstructor(test2, test1))

. MSDN InjectionConstructor constructor.

+3

, . ?

container.RegisterType<ITfsVcPromotionManager, TfsVcPromotionManager>(
    new InjectionConstructor(test2, test1)
);
+3

All Articles