小编Jac*_*oos的帖子

ServiceStack ResolveService

所以我的问题围绕调用以下url中描述的apphost.ResolveService: 从Razor调用ServiceStack服务

我在_Layout.cshtml中

显然下面的代码工作得很好,但正如上面的url中的答案所示,它有点愚蠢

SMSGateway.Services.EntityCollectionResponse response = 
    new ServiceStack.ServiceClient.Web.JsonServiceClient(
        "http://localhost:1337/")
        .Get<SMSGateway.Services.EntityCollectionResponse>(
            "/entities");
Run Code Online (Sandbox Code Playgroud)

所以这给了我一个实体列表:)但不是最优的...所以这是我尝试以正确的方式做到这一点

var response = ConsoleAppHost.Instance
    .ResolveService<SMSGateway.Services.EntityService>(
        HttpContext.Current).Get(
            new SMSGateway.Services.EntitiesRequest());

// SMSGateway.Services.EntityCollectionResponse response =
//     base.Get<SMSGateway.Services.EntityService>().Get(
//         new SMSGateway.Services.EntitiesRequest());

foreach (var entity in response.Result)
{
    <li>
        <a href="@entity.MetaLink.Href">
            @Html.TitleCase(entity.Name) entities
        </a>
    </li>
}
Run Code Online (Sandbox Code Playgroud)

好的,我得到的错误如下:

错误CS0122:由于其保护级别,ConsoleAppHost无法访问....

这是预期的吗?我在考虑是否这不是我可能不允许在_Layout.cshtml文件中调用它的情况?

进一步阅读带我进入了.NET 2.0中的InternalVisibleTo Testing Internal Methods文章

我觉得非常有趣:P但没有雪茄:)

inversion-of-control dto razor servicestack

1
推荐指数
1
解决办法
368
查看次数

标签 统计

dto ×1

inversion-of-control ×1

razor ×1

servicestack ×1