dependency injection for System.Web.Http.APIcontrollerin umbraco 8
Can anyone help with dependency injection for System.Web.Http.APIcontroller in umbraco 8? I have tried light injection and autofac but nothing worked. always caught with an error below
{
"Message": "An error has occurred.",
"ExceptionMessage": "An error occurred when trying to create a controller of type 'MyController'. Make sure that the controller has a parameterless public constructor.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": " at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()",
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Type 'Integration.Controllers.MyController' does not have a default constructor",
"ExceptionType": "System.ArgumentException",
"StackTrace": " at System.Linq.Expressions.Expression.New(Type type)\r\n at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"
}
I have resolved the issue by using UmbracoApiController and i have registerd my services using IUserComposer so dependency injection works fine as expected. after all, UmbracoApiController is inheriting System.Web.Http.ApiController, so it is working fine as expected. also UmbracoApiController helps with routing.
dependency injection for System.Web.Http.APIcontrollerin umbraco 8
Can anyone help with dependency injection for System.Web.Http.APIcontroller in umbraco 8? I have tried light injection and autofac but nothing worked. always caught with an error below
I have resolved the issue by using UmbracoApiController and i have registerd my services using IUserComposer so dependency injection works fine as expected. after all, UmbracoApiController is inheriting System.Web.Http.ApiController, so it is working fine as expected. also UmbracoApiController helps with routing.
is working on a reply...