Hi,
can somebody please verify this peace of code?
New Console App
Install-Package Microsoft.AspNet.WebApi.OwinSelfHost
Install-Package WebAPIContrib.IoC.CastleWindsor
Navigate to http://localhost: 12345/api/hello/world
Results in:
An error occurred when trying to create a controller of type 'HelloController'. Make sure that the controller has a parameterless public constructor.
No matter which Web API version or host I choose, I get this error.
Using other IoC Containers it works.
Thanks,
Alex
internal class Program {
static void Main(string[] args) {
var server = WebApp.Start<Startup>("http://localhost:12345");
Console.ReadLine();
server.Dispose();
}
}
public class Startup {
public void Configuration(IAppBuilder app) {
var config = new HttpConfiguration();
var container = new WindsorContainer();
container.Register(Component.For<IDepedency>().ImplementedBy<Dependency>()));
config.DependencyResolver = new WindsorResolver(container);
config.Routes.MapHttpRoute("default", "api/{controller}/{id}", new { Id = RouteParameter.Optional });
app.UseWebApi(config);
}
}
public interface IDepedency {
string Do(string input);
}
public class Depedency : IDepedency {
public string Do(string input) {
return string.Format("Hello {0}", input);
}
}
public class HelloController : ApiController {
readonly IDepedency _depedency;
public HelloController(IDepedency depedency) {
_depedency = depedency;
}
public HttpResponseMessage Get() {
return Request.CreateResponse(HttpStatusCode.OK, _depedency.Do("World"));
}
}
--
You received this message because you are subscribed to the Google Groups "WebApiContrib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webapicontri...@googlegroups.com.
To post to this group, send email to webapi...@googlegroups.com.
Visit this group at http://groups.google.com/group/webapicontrib.
For more options, visit https://groups.google.com/groups/opt_out.
Btw: this test doesn’t test the controller + IContactRepository:
When adding a ctor with IContactRepository dependency to the controller, it results in a HTTP 500 result.
Alex
--
You received this message because you are subscribed to the Google Groups "WebApiContrib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
webapi...@googlegroups.com.
Visit this group at http://groups.google.com/group/webapicontrib.
For more options, visit https://groups.google.com/groups/opt_out.
Tried 0.9.3 and 0.9.4.0 with the same results.
Looks like I’m doing something wrong in general.
When adding this, it works:
container.Register(Component.For<HelloController>().ImplementedBy<HelloController>());
But that shouldn’t be necessary, right?
Thanks,
Alex
As far as I know It's necessary. Castle can resolve only the registered components (it's not mandatory for unity).
So you have to register all controllers
.u
Thanks,
Alex
From: webapi...@googlegroups.com [mailto:webapi...@googlegroups.com]
On Behalf Of Alexander Zeitler
Sent: Mittwoch, 18. Dezember 2013 21:21
To: webapi...@googlegroups.com
Subject: RE: WindsorResolver issues
Btw: this test doesn’t test the controller + IContactRepository: