简体   繁体   English

我可以在Sitecore上的共享环境中运行的两个不同的.NET MVC站点中使用ServiceStack吗?

[英]Can I use ServiceStack in two different .NET MVC sites running in a shared environment on Sitecore?

We are delivering an ASP.NET MVC application built with Sitecore to a client that deploys the application to a multi site/tenant Sitecore installation. 我们将使用Sitecore构建的ASP.NET MVC应用程序提供给客户端,该客户端将应用程序部署到多站点/租户Sitecore安装。

We make heavy use of ServiceStack as we do on most of our projects, but have run into an issue now. 我们在大多数项目中都大量使用ServiceStack,但现在遇到了一个问题。 Another application in the Sitecore setup is also using ServiceStack. Sitecore设置中的另一个应用程序也使用ServiceStack。 This causes the error: 这会导致错误:

[InvalidDataException: AppHostBase.Instance has already been set]

Which makes perfect sense really, because all files for all the applications in the Sitecore installation is in the same physical folder on disk. 这真的很有道理,因为Sitecore安装中所有应用程序的所有文件都在磁盘上的同一物理文件夹中。 Meaning we share DLL's and everything. 意思是我们共享DLL和一切。

So this other project initializes before ours and when we then try to register our services we get the above error. 所以这个其他项目在我们之前初始化,然后当我们尝试注册我们的服务时,我们得到了上述错误。

Is there any way I can work around this? 有什么方法可以解决这个问题吗? Can I somehow register my services on the already existing AppHostBase.Instance ? 我可以以某种方式在现有的AppHostBase.Instance上注册我的服务吗?

Two things that might be worth noting: 有两件事可能值得注意:

  1. We do not have any influence on the setup of the Sitecore environment. 我们对Sitecore环境的设置没有任何影响。

  2. We can work together with the other team using ServiceStack if something has to be done in both projects. 如果必须在两个项目中完成某些事情,我们可以使用ServiceStack与其他团队一起工作。

Preferably you would tell ServiceStack all the assemblies with Services you want registered in your AppHost constructor, eg: 您最好告诉ServiceStack所有具有您想要在AppHost构造函数中注册的服务的程序集,例如:

public class AppHost : AppHostBase
{
    //Tell ServiceStack the name of your app and which assemblies to scan for services
    public AppHost() : base("Hello ServiceStack!", 
       typeof(ServicesFromDll1).Assembly,
       typeof(ServicesFromDll2).Assembly
       /*, etc */) {}

    public override void Configure(Container container) {}
}

But you can dynamically Register Services outside of ServiceStack with: 但您可以在ServiceStack之外动态注册服务:

HostContext.ServiceController.RegisterService(typeof(MyService));

Or register all Services in an Assembly with: 或者在装配中注册所有服务:

HostContext.ServiceController.
    RegisterServicesInAssembly(typeof(MyService).Assembly);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM