An object in the controller is not entered 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>
<resource uri="config://spring/objects"/>
</context>
<objects configSource="App_Config\Spring.config" />
</spring>
Spring.config:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<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
{
private ClassA ObjectA { get; set; }
Problem:
At run time, ObjectA is not injected and remains null, which causes a complete exception in the code.
Alternative: I can manually initialize the Spring object and get it with the following code.
var ctx = ContextRegistry.GetContext();
var objectA = ((IObjectFactory)ctx).GetObject("ObjectImpl") as ClassA;
source
share