Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pointcut 使用异常问题 #6

Closed
Wisehit opened this issue Jun 3, 2020 · 3 comments
Closed

pointcut 使用异常问题 #6

Wisehit opened this issue Jun 3, 2020 · 3 comments

Comments

@Wisehit
Copy link

Wisehit commented Jun 3, 2020

[Pointcut(Class = "*Controller", Method = "Get*")]

The requested service '***.HomeController' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency
再homecontroller 中添加了getuser 无法正常使用

@yuzd
Copy link
Owner

yuzd commented Jun 4, 2020

controller层交给autofac处理了吗?
Aspnetcore版本?

@Wisehit
Copy link
Author

Wisehit commented Jun 4, 2020

controller 是托管给autofac 不使用pointcut 能够正常使用,加上了就不能创建homecontroller 对象了

@yuzd
Copy link
Owner

yuzd commented Jun 4, 2020

升级到最新版本 3.1.4

image

//这行代码代表 controller的实例的创建交给autofac容器处理 
     services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
//除了上面那段代码以外,只能实现autofac去创建controller对象 ,但是必须得打【Compoment】标签注册到autofac容器才行

 [Component]
public class HomeController : ControllerBase
{

}

@yuzd yuzd closed this as completed Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants