How do I configure a NULL object in Spring.Net

2019-05-25 05:47发布

问题:

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>

回答1:

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


标签: spring.net