简体   繁体   中英

Error resolving c# Unity constructor

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM