views:

52

answers:

2

I am a beginner using castle windsor; and kinda introduced to it with Apress Pro Mvc book. In the project that I am working at; I use castlewindsor controller factory instead of mvc controller factory; so i can have parametrized constructors and i can inject the dependencies. Is there a way to tell the windsorcontroller factory to inject the values to the properties of the controller class without going through constructor? The reason I want to do this is because I have Logging dependency; Emailler Dependency; Database Dependency; Theme Engine dEpendency; and I dont want to use this many parameters parameter in the constructor.

+2  A: 

By default, when Windsor resolves a service implementation, it will populate all properties with public setters that it can satisfy.

However, take notice that sometime it does make sense to put the dependency resolving in the constructor, for that fact that it guarantees that any instance will always be in a valid state. Consider Unit Testing scenario, where the person writing the test will go crazy about the need to know which dependencies should be supplied. When all dependencies goes into the c'tor, the tester will have no choice but to supply the tested instance with all the required dependencies (as stubs or mocks).

Anyway, as for your question, Windsor support C'tor and property injection by default

Ken Egozi
and if it doesnt fill the properties, but the constructor; where should I be looking at ?
I'd say - post your code to Windsor's user group. You'll probably get quick help in no time
Ken Egozi
+1  A: 

Castle Windsor will automatically fill any properties with public setters that it knows how to fill.

This means if you have a class

public MyClass {
  public SomeDependency {get; set;}
}

As long as the container is configured to know how to resolve SomeDependency it will attempt to resolve and inject it.

Sometimes I've found this default behavior to be hassle. This facility will give you finer grained control over the process.

George Mauer