1

I am using Property Injections in my code. When I am using the classes I ended checking on entry to each functions if my properties are not null, and I ended with a lot checks in each function.

What are recommendation in this case? how to make the validation more nicer , or should I make the validation at all ? Maybe there is some not null property ?

Thanks

Night Walker
  • 20,638
  • 52
  • 151
  • 228

2 Answers2

4

If your dependencies are mandatory, make them mandatory.

Container.Register(Component.For<Foo>().Properties(PropertyFilter.RequireAll));

That way Windsor will ensure that all the properties are satisfied before it gives you back the object.

Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
1

If the dependency is not optional and you don't have reasonable local default then don't use Property Injection and use Constructor Injection instead.

Castle Windsor will throw if it is unable to resolve the dependencies. If you don't want to depend on this Castle feature then you should verify if dependencies passed to the constructor are not nulls.

empi
  • 15,755
  • 8
  • 62
  • 78