1

Question Background:

I am currently configuring a Unity container and am having issues setting the constructor of a class.

The class in question's constructor is set as shown. It takes in 3 string parameters and then 2 objects that I am setting up in the container.

public VersionControlFacade(string serverPath, string username, string password, IConnectionManager connectionManager, IPromoManager promoManager)

The configured Unity container for the above class is as shown:

container.RegisterType<IPromoManager, promotionManager>();
container.RegisterType<IConnectionManager, connectionManager>();
container.RegisterType<ITfsVersionControlFacade, TfsVersionControlFacade>(new InjectionConstructor(connectionString, username, password));

The Error:

Currently when trying to resolve the UnityContainer object, the following exception is being thrown:

The type VersionControlFacade does not have a constructor that takes the parameters (String, String, String)

I understand this, I am indeed passing in two other parameters, but it was my belief that as I have registered IPromoManager and IConnectionManager that these would be resolved and automatically injected into the VersionControlFacade constructor?

Can anyone tell me where the logic is wrong here, and what I can do to resolve it?

1
  • Your other question (very similar to this one) stackoverflow.com/questions/21675845/… shows that maybe you have a naming problem? You implement VersionControlService even though the constructor you're interested in is VersionControlFacade? Commented Mar 5, 2014 at 16:52

1 Answer 1

2

I believe you need:

container.RegisterType<ITfsVersionControlFacade, TfsVersionControlFacade>(new InjectionConstructor(connectionString, username, password, typeof(IConnectionManager), typeof(IPromoManager)));

See

Unity InjectionConstructor for multiparam constructor overriding only single one

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.