문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top