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

有办法实现动态控制器并路由吗? #38

Open
qcjxberin opened this issue Oct 25, 2020 · 25 comments
Open

有办法实现动态控制器并路由吗? #38

qcjxberin opened this issue Oct 25, 2020 · 25 comments
Labels

Comments

@qcjxberin
Copy link

有办法实现动态控制器并路由吗?

@qcjxberin
Copy link
Author

我的意思是控制器本身也是动态的.

@NMSAzulX
Copy link
Collaborator

控制器可以是动态的,你生成控制器类之后注册进去就行了。

@NMSAzulX
Copy link
Collaborator

首页的动图就是展示的这个操作,如果打不开需要自己改一下HOST

@qcjxberin
Copy link
Author

首页的动态那效果有DEMO代码吗?

@NMSAzulX
Copy link
Collaborator

就是我发的那个链接,是 core31WebAPi 项目

@qcjxberin
Copy link
Author

好的,谢谢

@qcjxberin
Copy link
Author

你给的Demo好像没有用//仅仅注册组件
NatashaInitializer.Initialize();
//注册+预热组件 , 之后编译会更加快速
await NatashaInitializer.InitializeAndPreheating();这些来预热的

@qcjxberin
Copy link
Author

另外这种方式能用在mvc上吗?

@NMSAzulX
Copy link
Collaborator

你给的Demo好像没有用//仅仅注册组件
NatashaInitializer.Initialize();
//注册+预热组件 , 之后编译会更加快速
await NatashaInitializer.InitializeAndPreheating();这些来预热的

使用最新版 Natasha 例子没有更新。

MVC 上没做过调研,理论上可以使用。因为 MVC 组件要比 API 组件要多。

@NMSAzulX
Copy link
Collaborator

image

NatashaInitializer.InitializeAndPreheating(); 代替下面3句。

@qcjxberin
Copy link
Author

我先试下看看

@qcjxberin
Copy link
Author

如果有使用Autofac的话,报错了
image

@NMSAzulX
Copy link
Collaborator

嗯,这个需要把注册的实例保留,在添加动态路由的时候再注册一下。

@qcjxberin
Copy link
Author

具体应该怎么写代码的?

@NMSAzulX
Copy link
Collaborator

请提供更多的信息,startup.cs 和 TestController

@NMSAzulX
Copy link
Collaborator

程序代码可以打包发我邮箱 2765968624@qq.com

@qcjxberin
Copy link
Author

TestController就是demo里的,其他的代码就是默认有使用autofac的这种,现在手上的项目框架太大了,不方便发。

@NMSAzulX
Copy link
Collaborator

@qcjxberin
Copy link
Author

能解决了麻烦在这里回复一下。

@NMSAzulX
Copy link
Collaborator

这个属于 Autofac 的问题,如果您着急使用请先联系 Autofac 的团队询问。

@fory77
Copy link

fory77 commented Apr 11, 2024

@fory77
Copy link

fory77 commented Apr 17, 2024

https://github.com/dotnetcore/Natasha/blob/master/samples/Core31WebApi/Controllers/NatashaController.cs#L26

这地址404了,请问webapi的示例项目还有吗

https://github.com/dotnetcore/Natasha/blob/Achive31/samples/Core31WebApi/Controllers/NatashaController.cs

多谢张老师, 不过新版里貌似没有ScriptHelper,是有什么新的替代吗?还是需要我参考老版代码手动实现一下?我是.net6的项目

@NMSAzulX
Copy link
Collaborator

https://github.com/dotnetcore/Natasha/blob/master/samples/Core31WebApi/Controllers/NatashaController.cs#L26

这地址404了,请问webapi的示例项目还有吗

https://github.com/dotnetcore/Natasha/blob/Achive31/samples/Core31WebApi/Controllers/NatashaController.cs

多谢张老师, 不过新版里貌似没有ScriptHelper,是有什么新的替代吗?还是需要我参考老版代码手动实现一下?我是.net6的项目

获取类名的工具类而已,自己实现一个就行,名字没有特殊用法,随便取。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants