Fabiano
Fabiano

Reputation: 5194

Use Property as factory-method in Spring.Net

Is there a way to use a static property of a class as the factory-method for a object definition?

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

Using this config a exception is thrown:

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

Upvotes: 4

Views: 2123

Answers (1)

BennyM
BennyM

Reputation: 2856

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

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

Upvotes: 6

Related Questions