以编程方式创建应用程序和服务 [英] Programmatically create Applications and Services
问题描述
对于我们的新项目,我们必须支持多租户方案.建议每个租户使用一个应用程序是最安全的模型,因此我们在逻辑上将我们的应用程序分为 SystemApps 和 TenantApps
For our new project we have to support a multi-tenant scenario. It has been recommended that having an application per tenant is the safest model, so we have logically separated our Apps into SystemApps and TenantApps
应该通过
结构:/TenantApps_ {tenantId}/SomeTenantSvc
我们打算提供一个系统服务,该服务可创建和删除客户端应用程序并检查其运行状况.这些应用程序将具有默认服务,该服务将根据其订阅依次启动/停止其应用程序中的其他服务.
We intend to have a System service that creates and remove client applications and checks their health. These applications will have a default service which in turn starts/stops other services within their application based upon their subscriptions.
从理论上讲一切都很好,但是我一生无法找到从代码创建新应用程序和服务的位置.我认为这与FabricRuntime有关-但更详细的信息使我难以理解.
All good in theory, but I can't for the life of me find where to create new applications and services from code. I Assume it's something to do with the FabricRuntime - but the finer details elude me.
如果任何人都可以举一个例子或链接到正确的文档,那么我将不胜感激.
If anyone is able to give an example or link to the correct documentation then I would be grateful.
推荐答案
This is how to do create an application instance in code, using an existing application type:
string appName = "fabric:/MyApplication";
string appType = "MyApplicationType";
string appVersion = "1.0.0";
var fabricClient = new FabricClient();
// Create the application instance.
try
{
ApplicationDescription appDesc = new ApplicationDescription(new Uri(appName), appType, appVersion);
await fabricClient.ApplicationManager.CreateApplicationAsync(appDesc);
}
catch (AggregateException ae)
{
}
对于服务:
// Create the stateless service description. For stateful services, use a StatefulServiceDescription object.
StatelessServiceDescription serviceDescription = new StatelessServiceDescription();
serviceDescription.ApplicationName = new Uri(appName);
serviceDescription.InstanceCount = 1;
serviceDescription.PartitionSchemeDescription = new SingletonPartitionSchemeDescription();
serviceDescription.ServiceName = new Uri(serviceName);
serviceDescription.ServiceTypeName = serviceType;
// Create the service instance. If the service is declared as a default service in the ApplicationManifest.xml,
// the service instance is already running and this call will fail.
try
{
await fabricClient.ServiceManager.CreateServiceAsync(serviceDescription);
}
catch (AggregateException ae)
{}
这篇关于以编程方式创建应用程序和服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!