1

Question Back ground:

I have a project consisting of a DLL, a web service and a test project. Currently I'm simply trying to set the web service constructor string parameter through the use of Unity.

The issue & error:

The following shows the constructor structure of the web service class 'VersionControlFacade':

 private string _url;

 public VersionControlService()
 {
 }

 public VersionControlService(string url)
 {
    _url = url;
 }

If I simply pass the 'url' parameter as shown in the following code it is fine:

 var newVersionControlFacade = new VersionControlFacade(@"http://somelink.com");

When I try and pass it using my Unity IoC container as shown:

 var container = new UnityContainer();
 container.RegisterType<IVersionControlFacade, ProxyHandler>();
 container.RegisterType<Proxy>();
 container.RegisterType<VersionControlService>(new InjectionConstructor(@"http://somelink.com"));
 return container.Resolve<IVersionControlFacade>();

The following error is being throw stating that the web service does not contain a constructor that takes a string parameter even though it clearly does.:

Result Message:

Test method Test_Unity threw exception: System.InvalidOperationException: The type VersionControl.WebService.VersionControlService does not have a constructor that takes the parameters (String).

Can anyone steer me in the right direction here? Do I need to re-add the web reference for it to see this new constructor?

5
  • Try reading the web reference, Also to debug try to call the class directly, at least you will see if the constructor is being seen. Commented Feb 10, 2014 at 11:32
  • 1
    Here is a sample with injection constructor and it works fine for me - dotnetfiddle.net/Vb1uEK Commented Feb 10, 2014 at 11:33
  • @LawrenceThurman Not sure I understand by 'reading the web reference could you elaborate please. I have called the class directly and it works, it just seems to be trying to set it through Unity. Commented Feb 10, 2014 at 11:54
  • @SergeyLitvinov Thanks for your example. I have used unity the way you have shown and the way I have shown many times, but I've never attempted to set a web service constructor using Unity and this is where the issue is coming in. Commented Feb 10, 2014 at 11:55
  • sorry - re-add the web service. Commented Feb 10, 2014 at 12:06

0

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.