c# - How to integrate WebApi 2 with Spring.Net -


im trying integrate webapi 2 spring.net not success. have tried:

public class mvcapplication : springmvcapplication {     protected void application_start()     {         xmlconfigurator.configure();          arearegistration.registerallareas();         globalconfiguration.configure(webapiconfig.register);         filterconfig.registerglobalfilters(globalfilters.filters);         routeconfig.registerroutes(routetable.routes);         bundleconfig.registerbundles(bundletable.bundles);     } } 

when creating springwebapidependencyresolver instance, i'm getting exception:

error creating context 'spring.root': request not available in context

public static class webapiconfig {     public static void register(httpconfiguration config)     {         config.dependencyresolver = new springwebapidependencyresolver(contextregistry.getcontext());          config.routes.maphttproute(             name: "defaultapi",             routetemplate: "api/{controller}/{id}",             defaults: new { id = routeparameter.optional }         );     } } 

im using spring.net 2.0.1

now working, following line not needed:

config.dependencyresolver = new springwebapidependencyresolver(contextregistry.getcontext()); 

this implementation based on spring.net example:

public class mvcapplication : springmvcapplication {     protected void application_start()     {         // more config...         globalconfiguration.configure(webapiconfig.register);         // more config...     }      protected override system.web.http.dependencies.idependencyresolver buildwebapidependencyresolver()     {         var resolver = base.buildwebapidependencyresolver();          var springresolver = resolver springwebapidependencyresolver;          if (springresolver != null)         {             var resource = new assemblyresource(                 "assembly://assemblyname/namespace/childcontrollers.xml");             springresolver.addchildapplicationcontextconfigurationresource(resource);         }          return resolver;     } } 

i prefered keep common webapi configuration:

public static class webapiconfig {     public static void register(httpconfiguration config)     {         config.routes.maphttproute(             name: "defaultapi",             routetemplate: "api/{controller}/{id}",             defaults: new { id = routeparameter.optional }         );     } } 

for registration of controllers in ioc container same mvc integration:

<object type="namespace.prefixcontroller, assemblyname" singleton="false" >     <property name="dependency1" ref="dependency1" /> </object> 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -