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

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

问题描述

我有一个解决方案,包括一个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


  • 单页的应用程序,让数 CSHTML 文件住在APPHOST项目。这是值得学习曲线?

  • 有单独的项目调用Web服务。那不是很无效的,考虑到他们生活在同一个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. 为网站项目必须剃刀启用。它必须有一个例子 ServiceStack.Razor 的引用,因此 .cshtml 编译。

正如@mythz指出,添加 ServiceStack.Razor.BuildTask 来precompile剃刀文件。这是必要的,让他们包括 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 例如:

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 } });


  • 到目前为止,它一直都是关于剃刀.cshtml文件。也包括服务,例如对于更复杂的观点,只是将它添加到了 APPHOST():基地(...),或者如果你想要一个preFIX对这些服务的使用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文件剃刀没有单独的命名空间,所以hello.cshtml在外部DLL与主APPHOST的同名文件冲突。通过将(在外部DLL)中的所有文件CSHTML一个子文件夹下,这将帮助,因为该文件夹将是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剃刀文件中单独的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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