Programmatically create Applications and Services

夙愿已清 提交于 2019-12-13 17:33:01

问题


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

Where the tenant services should be accessible (internally) via

fabric:/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.

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.


回答1:


Here's the documentation.

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

And for services:

// 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)
{}


来源:https://stackoverflow.com/questions/43719599/programmatically-create-applications-and-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!