An input object with a request object in a prototype object

I use Spring.Net in my ASP.NET MVC application, where controllers should be defined as prototypes (not single). I have objects that should have a request scope (a new object for each request). Is there any way to enter them into the controller?

  <object type="xx.CompanyController, xx" singleton="false">
    <property name="Service" ref="ServiceA" />
  </object>

  <object id="ServiceA" type="xx.ServiceA, xx" scope="request"/>    
    <property name="ObjectB" ref="ObjectB" />
  </object>

  <object id="ObjectB" type="xx.ObjectB, xx" scope="request"/>

Similarly, all objects except controllers are considered as single objects. ObjectB does not have to be a prototype because it is referenced by other objects that need to share the same instance. Removing singleton = "false" from the controller and adding scope = "request" also does not work (the controller is treated as singleton).

I am using Spring.Net 1.3.1 with MvcApplicationContext

+3
1

ControllerFactory .

protected void Application_Start()
{
//...
    ControllerBuilder.Current.SetControllerFactory(new IoCControllerFactory());
//...
}

IoCControllerFactory DefaultControllerFactory

public class IoCControllerFactory : DefaultControllerFactory

GetControllerInstance

protected override IController GetControllerInstance (RequestContext requestContext, Type controllerType)
    {
        ObjectTypeUtility.ArgumentIsNull(controllerType, "controllerType", true);
         if (!typeof(IController).IsAssignableFrom(controllerType))
             throw new ArgumentException(string.Format(
                       "Type requested is not a controller: {0}",
                       controllerType.Name), 
                        "controllerType");    

            IController controller = IoCWorker.Resolve(controllerType) 
                                      as IController;                
            return controller;

    }

IoCWorker - , Resolve , Unity, IoCWorker - , .

ctor .

.

0

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


All Articles