public CodePackageActivationContextProvider( ServiceManifestElement manifest, IServiceActivationContext activationContext, ICodePackageActivationContextReader activationContextReader) { this.manifest = manifest ?? throw new ArgumentNullException(nameof(manifest)); this.activationContext = activationContext ?? throw new ArgumentNullException(nameof(activationContext)); this.activationContextReader = activationContextReader ?? throw new ArgumentNullException(nameof(activationContextReader)); }
public ICodePackageActivationContext Read( IServiceActivationContext activationContext, ServiceManifestElement manifest) { if (activationContext is null) { throw new ArgumentNullException(nameof(activationContext)); } if (manifest is null) { throw new ArgumentNullException(nameof(manifest)); } var location = Assembly.GetEntryAssembly()?.Location; var path = Path.GetDirectoryName(location) ?? Path.GetPathRoot(location); /* * We don't read real code packages because there is no * easy and reliable way to find out inside what code package * current service is located. * * So to avoid unnecessary complexity we simple create custom * code package with the name Code. */ var codePackage = new CodePackageAccessor( new CodePackageFactory() .Create( new CodePackageElement { Manifest = manifest, Name = activationContext.CodePackageName, Version = activationContext.CodePackageVersion })) { /* * Here we override path relative to PackageRoot directory with the path * where actual binaries are located. * * This is required to make sure all file searches relative to CodePackage * are done in the binaries directory */ Path = path } .Instance; return(new CodePackageActivationContext( activationContext.ApplicationName, activationContext.ApplicationTypeName, activationContext.ActivationContextId, activationContext.LogDirectory, activationContext.TempDirectory, activationContext.WorkDirectory, activationContext.CodePackageName, activationContext.CodePackageVersion, manifest.Name, manifest.Version, new ApplicationPrincipalsDescription(), new[] { codePackage }, CreatePackagesFrom(manifest.ConfigurationPackages, new ConfigurationPackageFactory()), CreatePackagesFrom(manifest.DataPackages, new DataPackageFactory()), CreateServiceTypesDescriptionsFrom(manifest.ServiceTypes), CreateServiceEndpointsFrom(manifest.Resources.Endpoints))); }