Use property as a factory method in Spring.Net

Is it possible to use the static property of a class as a factory method to define an object?

  <object id="MyObject" type="MyNamespace.Factory, MyAssembly" factory-method="FactoryObject"  /> 
  <!-- "FactoryObject" is a Property (with getter) of the class "Factory" -->

Using this configuration, an exception is thrown:

Error creating context 'spring.root': Cannot find the corresponding factory method 'FactoryObject on Type [MyNamespace.Factory]

+3
source share
1 answer

Unconventional, but you can use the property if you use the generated get method by the compiler.

<object id="MyObject" type="MyNamespace.Factory, MyAssembly" factory-method="get_FactoryObject"  />
+4
source

Source: https://habr.com/ru/post/1728062/


All Articles