Reputation: 1751
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 removes 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.
Upvotes: 1
Views: 1067
Reputation: 11470
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)
{}
Upvotes: 5