简体   繁体   中英

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.

We make heavy use of ServiceStack as we do on most of our projects, but have run into an issue now. Another application in the Sitecore setup is also using 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. Meaning we share DLL's and everything.

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 ?

Two things that might be worth noting:

  1. We do not have any influence on the setup of the Sitecore environment.

  2. We can work together with the other team using ServiceStack if something has to be done in both projects.

Preferably you would tell ServiceStack all the assemblies with Services you want registered in your AppHost constructor, eg:

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:

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

Or register all Services in an Assembly with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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