单独项目中的 ServiceStack Razor 文件 [英] ServiceStack Razor files in separate project

查看:23
本文介绍了单独项目中的 ServiceStack Razor 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 ServiceStack 后端组成的解决方案,具有常规设置(AppHost、ServiceInterface 和 ServiceModel),以及一个 winforms 应用程序和一个使用服务的 iOS 应用程序.

I have a solution consisting of a ServiceStack back-end, with the regular setup (AppHost, ServiceInterface and ServiceModel), and both a winforms app and a iOS app consuming services.

现在我想做一名网络管理员,并且正在寻找有关如何构建此内容的建议.我想保持 apphost 项目小,正如 SS 文档所说

Now I'd like to make a web-admin, and am looking for advice on how to structure this. I'd like to keep the apphost project small, as SS docs say

理想情况下,根级 AppHost 项目应该保持轻量级和无需实施.

Ideally the root-level AppHost project should be kept lightweight and implementation-free.

所以我想将网络管理员放在一个单独的项目中,包括所有 .cshtml 和内容等等.

So I'd like to have the web-admin in a separate project, with all the .cshtml and content and it all.

这可能吗?不建议?有任何想法吗?

Is this possible? Not recommended? Any ideas?

我能想到的一些替代方案是

Some alternatives I can think of are

  • single-page-app,让少数 cshtml 文件存在于 AppHost 项目中.这值得学习曲线吗?
  • 让单独的项目调用 Web 服务.考虑到它们生活在同一个网络服务器上,这不是非常无效吗?还是应该将其视为优势,因为它使所有内容松散耦合?
  • single-page-app, let the few cshtml files live in the AppHost-project. Is this worth the learning curve?
  • have the separate project call the web-services. Wouldn't that be very ineffective, considering that they live on the same web-server? Or should it be considered an advantage, since it makes everything loosely coupled?

推荐答案

我想为初学者提供一个更完整的答案:

I'd like to provide a more complete answer for beginners:

  1. 网站项目必须启用 razor.例如,它必须引用 ServiceStack.Razor,这样 .cshtml 才能编译.

正如@mythz 所指出的,添加 ServiceStack.Razor.BuildTask 来预编译 razor 文件.这是让它们包含LoadFromAssemblies 参数

As pointed out by @mythz, add the ServiceStack.Razor.BuildTask to precompile the razor files. This is necessary to get them included the LoadFromAssemblies parameter

在主 AppHost 中,使用 LoadFromAssemblies 指定要在另一个程序集中找到 Razor 文件,例如:

In the main AppHost, specify that Razor files are to be found in the other assembly with LoadFromAssemblies e.g:

    this.Plugins.Add(new RazorFormat { LoadFromAssemblies = { typeof(ActivityServer.Admin.AdminServices).Assembly } });

  • 到目前为止,所有内容都与 Razor .cshtml 文件有关.还包括服务,例如对于更复杂的视图,只需将其添加到 AppHost() : base(...),或者如果您想要这些服务的前缀,请使用 AppHost.RegisterService.

  • So far it's been all about the Razor .cshtml files. To also include services, e.g. for more complex views, just add this to the AppHost() : base(...), or if you want a prefix to those services use AppHost.RegisterService.

    需要指出的一点是,外部 DLL 中的 Razor 文件没有单独的命名空间,因此外部 DLL 中的hello.cshtml"与主 AppHost 中的同名文件发生冲突.通过将所有 cshtml 文件(在外部 dll 中)放在一个子文件夹下,这会有所帮助,因为该文件夹将成为 URL 的一部分.

    One thing to point out is that there is no separate namespace for Razor files in the external DLL, so a "hello.cshtml" in the external DLL collides with a file with the same name in the main AppHost. By putting all cshtml files (in the external dll) under a sub-folder, that will help, because the folder will be part of the URL.

    这篇关于单独项目中的 ServiceStack Razor 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆