WindsorResolver issues

58 views
Skip to first unread message

Alexander Zeitler

unread,
Dec 18, 2013, 3:13:37 PM12/18/13
to webapi...@googlegroups.com

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"));

                               }

                }

 

 

 

 

Ali Kheyrollahi

unread,
Dec 18, 2013, 3:18:59 PM12/18/13
to webapi...@googlegroups.com
I made some changes to it as it had a memory leak. Can you please try using an older version of the nuget package (before my changes)?


--
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.

Alexander Zeitler

unread,
Dec 18, 2013, 3:20:50 PM12/18/13
to webapi...@googlegroups.com

Btw: this test doesn’t test the controller + IContactRepository:

https://github.com/WebApiContrib/WebApiContrib.IoC.CastleWindsor/blob/master/test/WebApiContrib.IoC.CastleWindsor.Tests/DependencyInjectionTests.cs#L42

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

Alexander Zeitler

unread,
Dec 18, 2013, 3:26:09 PM12/18/13
to webapi...@googlegroups.com

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

Ugo Lattanzi

unread,
Dec 18, 2013, 3:30:11 PM12/18/13
to webapi...@googlegroups.com

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

Alexander Zeitler

unread,
Dec 18, 2013, 3:31:25 PM12/18/13
to webapi...@googlegroups.com

Thanks,

 

Alex

Ali Kheyrollahi

unread,
Dec 18, 2013, 3:44:41 PM12/18/13
to webapi...@googlegroups.com
Yes it is necessary.

Alexander Zeitler

unread,
Dec 25, 2013, 11:16:40 AM12/25/13
to webapi...@googlegroups.com

 

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:

Reply all
Reply to author
Forward
0 new messages