2

In the particular project in which I'm working it is appropriate to to have a null log service object. Since this is configured in Spring.Net How do I configure my spring.net object to be null. This is what I'd like to do. Is it possible?

<objects xmlns="http://www.springframework.net">
  <!-- Messages -->

  <object id ="LogService">
    <null />
  </object>
Confused
  • 869
  • 1
  • 7
  • 16

1 Answers1

4

You can inject a null object :

<object id="MyObject">
  <property name="LogServer">
    <null/>
  </property>
</object>

To create a null object, you have to implement IFactoryObject and return null. http://www.springframework.net/doc-latest/reference/html/objects.html#objects-factory-extension

  • Bruno
bbaia
  • 1,193
  • 7
  • 8
  • Yep, this might be the easiest way to achieve what I want. Thanks. – Confused May 13 '11 at 12:44
  • @bbaia, I did a small test and an `IFactoryObject` that returns null is results in an `FactoryObjectNotInitializedException` thrown by the container. See http://stackoverflow.com/a/9295326/322283 for details if your interested. – Marijn Feb 17 '12 at 15:52