Windsor Container Property Setter Injection
Hammet pointed out in the comments for Creating a simple Windsor facility that the whole premise of my TimeServiceFacility is silly.
Sorry, but I still don't get it why you used a facility to do that. You could get the same behavior by
- registering the timeservice as, well, a service
- having writable properties on components, like you do on HasTimeServiceProperty class.
it will be "injected" in the same way.
Interesting exercise, though.
This post is an attempt to correct a wrong. Windsor will do Property setter injection out of the box. Just follow what Hammet said to do a viola you get the same thing.
Add the TimeService as service component to the container:
Container.Current.AddComponent('timeservice', typeof(ITimeService), typeof(TimeService));
Here is a test that proves setter injection is working for components resolved from the container having a writeable ITimeService property:
1: [Test]
2: public void A_container_component_with_a_TimeService_property_should_have_the_TimeService_property_set_by_the_container()
3: { 4: Container.Current.AddComponent("has.timeservice", typeof(HasTimeServiceProperty)); 5:
6: HasTimeServiceProperty hasTimeServiceProperty = Container.Resolve<HasTimeServiceProperty>();
7:
8: hasTimeServiceProperty.TimeService.ShouldNotBeNull();
9: }
10:
11: public class HasTimeServiceProperty
12: { 13: private ITimeService _timeService;
14:
15: public ITimeService TimeService
16: { 17: get { return _timeService; } 18: set { _timeService = value; } 19: }
20: }
Feeling the love
I just wanted to take a moment to thank the community surrounding the Castle Project. You can tell how much people love using this framework by how much they are willing to pitch in to help each other out. Just take a browse around the user or developer groups and forums or IRC to find committers and users alike taking time to help each other use and make the project better, not to mention taking the time to point out fundamental flaws in blog posts.