The object in the controller is not getting injected at run time.
Web.config:
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
. . .
<!-- Spring Context Configuration -->
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects configSource="App_Config\Spring.config" />
</spring>
<!-- End Spring Context Configuration -->
Spring.config:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<!-- Crest is the WCF service to be exposed to the client, could not use a singleton -->
<object id="TestController" type="Project.Controllers.TestController, Project" singleton="false">
<property name="ObjectA" ref="ObjectImpl"/>
</object>
<object id="ObjectImpl" type="Project.Code.Implementations.ClassA, Project" singleton="false" />
</objects>
TestController:
public class TestController: Controller
{
// this object will be injected by Spring.net at run time
private ClassA ObjectA { get; set; }
Problem:
At runtime the ObjectA does not get injected and stays null, which cause null exception throughout the code.
Alternative: I can manually initialize the Spring object and get it's object using the following code.
var ctx = ContextRegistry.GetContext();
var objectA = ((IObjectFactory)ctx).GetObject("ObjectImpl") as ClassA;