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?

admdrew
  • 3,790
  • 4
  • 27
  • 39
user1352057
  • 3,162
  • 9
  • 51
  • 117
  • Your other question (very similar to this one) http://stackoverflow.com/questions/21675845/cannot-set-web-service-constructor-parameter shows that maybe you have a naming problem? You implement `VersionControlService` even though the constructor you're interested in is `VersionControlFacade`? – AndyG Mar 05 '14 at 16:52

1 Answers1

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

Community
  • 1
  • 1
Alan
  • 7,875
  • 1
  • 28
  • 48