Search code examples
c#dependency-injectioncastle-windsorioc-containerrestsharp

Castle Windsor register error with RestSharp.RestClient constructor


I try to register RestSharp dependencies using CastleWindsor. the RestClient class got three constructors:

public RestClient();

public RestClient(Uri baseUrl);

public RestClient(string baseUrl);

The problem occured when I pass parameter to constructor:

container.Register(Component.For<RestSharp.IRestClient>().ImplementedBy<RestSharp.RestClient>()
                .DependsOn(Dependency.OnValue("baseUrl", endpoint)));

The error says that it can't convert System.String to System.Uri when I pass endpoint as a string. When I pass endpoint as an Uri, error says that it can't convert System.Uri to System.String.

Any thoughts ?


Solution

  • The Dependency.OnValue has an overload that allows you to specify a type:

    Dependency.OnValue<System.Uri>(endpointAddress)