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

提供一个非 Controller/Action 的类库,宿主程序根据其方法签名提供 WebApi #9

Open
QJesus opened this issue Oct 24, 2019 · 3 comments

Comments

@QJesus
Copy link

QJesus commented Oct 24, 2019

如果是一个类库 dll,里面有方法,方法就是需要提供的 api 接口。
框架如何实现,按照其方法签名自动提供 api 接口?

@lamondlu
Copy link
Owner

@QJesus
你的意思是dll里面放的是Controller/Action的代码,你希望主程序能自动加载这些Controller/Action。
之前版本.NET Core里面可以使用services.ControllerAsService()这个方法来加载,但是前提是你的dll不是加载在Custom Load Context中,应该加载在Default Load Context中。不知道这样是否解答了你的问题,如果还有问题,可留言

@QJesus
Copy link
Author

QJesus commented Oct 24, 2019

类库 dll 中不是 Controller/Action 代码,仅为普通方法,比如下面的 Class1.HelloWorld 方法。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DemoPlugin
{
    public class Class1
    {
        public dynamic HelloWorld(int times)
        {
            var data = Enumerable.Range(0, times).Select(o => "hello world").ToArray();
            return data;
        }
    }
}

编译 DemoPlugin.Class1 后打包上传到宿主程序,点击启用,宿主解析该 dll 的方法后自动提供和方法签名一致的 api。

宿主程序应该如何实现?

@QJesus QJesus changed the title 根据方法签名提供接口? 提供一个非 Controller/Action 的类库,宿主程序根据其方法签名提供 WebApi Oct 24, 2019
@laosandegudai
Copy link

类库dll中不是控制器/动作代码,只有普通方法,有些下面的Class1.HelloWorld方法。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DemoPlugin
{
    public class Class1
    {
        public dynamic HelloWorld(int times)
        {
            var data = Enumerable.Range(0, times).Select(o => "hello world").ToArray();
            return data;
        }
    }
}

编译DemoPlugin.Class1后打包上传到宿主程序,单击启用,托管解析该dll的方法后自动提供和方法签名一致的api。

主机程序应该如何实现?

可参考abp动态api代理

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

3 participants