{
"Message": "出現錯誤。",
"ExceptionMessage": "嘗試創建“ProductController”型別的控制器時出錯。請確保控制器具有無引數公共建構式。",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": " 在 System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n 在 System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)\r\n 在 System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()",
"InnerException": {
"Message": "出現錯誤。",
"ExceptionMessage": "An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = ProductController (ReflectionActivator), Services = [TSC.WebApiX.Controllers.ProductController], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'TSC.WebApiX.Controllers.ProductController' can be invoked with the available services and parameters:\r\nCannot resolve parameter 'TSC.Service.ProductService productService' of constructor 'Void .ctor(TSC.Service.ProductService)'. (See inner exception for details.)",
"ExceptionType": "Autofac.Core.DependencyResolutionException",
"StackTrace": " 在 Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)\r\n 在 Autofac.Core.Resolving.InstanceLookup.Execute()\r\n 在 Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)\r\n 在 Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)\r\n 在 Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)\r\n 在 Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)\r\n 在 Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)\r\n 在 Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType)\r\n 在 Autofac.Integration.WebApi.AutofacWebApiDependencyScope.GetService(Type serviceType) 位置 C:\\projects\\autofac-webapi\\src\\Autofac.Integration.WebApi\\AutofacWebApiDependencyScope.cs:行號 76\r\n 在 System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)\r\n 在 System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)",
"InnerException": {
"Message": "出現錯誤。",
"ExceptionMessage": "None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'TSC.WebApiX.Controllers.ProductController' can be invoked with the available services and parameters:\r\nCannot resolve parameter 'TSC.Service.ProductService productService' of constructor 'Void .ctor(TSC.Service.ProductService)'.",
"ExceptionType": "Autofac.Core.DependencyResolutionException",
"StackTrace": " 在 Autofac.Core.Activators.Reflection.ReflectionActivator.GetValidConstructorBindings(IComponentContext context, IEnumerable`1 parameters)\r\n 在 Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)\r\n 在 Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)"
}
}
}
是依賴注入的問題嗎?具體是什么問題呢?
uj5u.com熱心網友回復:
一般的類會給你創建無參構造,這個東西有且必須存在,但是,當你手動創建有參構造后,類就不會幫你自動創建了,你可以手動創建下,public product..(){}uj5u.com熱心網友回復:
controller對service添加下參考轉載請註明出處,本文鏈接:https://www.uj5u.com/net/48022.html
標籤:C#
上一篇:net core System.Drawing is not supported on this platform.
