首页 新闻 搜索 专区 学院

abp 动态注入获取的接口 IApplicationService 调用里面的方法非常慢

0
悬赏园豆:10 [待解决问题]


public interface ITestAppService : IApplicationService
{
void Test1(List<int> list);
}

public class TestAppService : TESTAppServiceBase, ITestAppService
{
    public void Test1(List<int> list)
    {

    }
}

代码
public string Test(int count)
{
var list = Enumerable.Range(1, 10000).ToList();

        var msg = "";

        var sw = new Stopwatch();

        var test = IocManager.Instance.Resolve<TestAppService>();
        sw.Start();
        for (int i = 0; i < count; i++)
        {
            test.Test1(list);
        }
        msg += $"class: {sw.ElapsedMilliseconds}ms, ";

        var itest = IocManager.Instance.Resolve<ITestAppService>();
        sw.Restart();
        for (int i = 0; i < count; i++)
        {
            itest.Test1(list);
        }
        msg += $"interface: {sw.ElapsedMilliseconds}ms, ";

        ITestAppService newTest = new TestAppService();
        sw.Restart();
        for (int i = 0; i < count; i++)
        {
            newTest.Test1(list);
        }
        msg += $"new interface: {sw.ElapsedMilliseconds}ms, ";

        return msg;

    }

结果
调用 Test(1000)
class: 0ms, interface: 7321ms, new interface: 0ms,

Angel〆汐的主页 Angel〆汐 | 菜鸟二级 | 园豆:211
提问于:2019-11-26 17:13
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册