예제 #1
0
        /// <summary>
        /// <para>Associates the specified <paramref name="serviceTypeName" /> with the actual managed Type that implements it. </para>
        /// </summary>
        /// <param name="serviceTypeName">
        /// <para>The type name of the service type (as a string).  This should match the type of the service group type as specified in the manifests and/or
        /// the CreateService command.</para>
        /// </param>
        /// <param name="serviceTypeImplementation">
        /// <para>The qualified service Type that implements the specified <paramref name="serviceTypeName" />.</para>
        /// </param>
        /// <remarks>
        /// <para>Note that this mechanism for service type registration does not require a custom <see cref="System.Fabric.IStatelessServiceFactory" /> or
        /// <see cref="System.Fabric.IStatefulServiceFactory" /> to be provided at registration time.  Service Fabric will generate one at runtime and utilize
        /// it automatically.  If there is a need for a custom implementation of the factory, you can implement <see cref="System.Fabric.IStatelessServiceFactory" />
        /// or <see cref="System.Fabric.IStatefulServiceFactory" /> and then provide those via the corresponding factory registration methods
        /// (<see cref="System.Fabric.FabricRuntime.RegisterStatelessServiceFactoryAsync" /> or <see cref="System.Fabric.FabricRuntime.RegisterStatefulServiceFactoryAsync" />)</para>
        /// </remarks>
        public void RegisterServiceType(string serviceTypeName, Type serviceTypeImplementation)
        {
            this.ThrowIfDisposed();

            bool isStateful = FabricRuntime.ValidateParametersForRegisterServiceType(serviceTypeName, serviceTypeImplementation);

            Utility.WrapNativeSyncInvokeInMTA(() => this.RegisterServiceTypeHelper(isStateful, serviceTypeName, serviceTypeImplementation), "FabricRuntime.RegisterServiceType");
        }
예제 #2
0
        /// <summary>
        /// <para>Asynchronously associates the specified serviceTypeName with the actual managed Type that implements it, with the specified <paramref name="timeout" />
        /// and <paramref name="cancellationToken" /></para>
        /// </summary>
        /// <param name="serviceTypeName">
        /// <para>The type name of the service type (as a string).  This should match the type of the service group type as specified in the manifests
        /// and/or the CreateService command.</para>
        /// </param>
        /// <param name="serviceTypeImplementation">
        /// <para>The qualified service Type that implements the specified <paramref name="serviceTypeName" />.</para>
        /// </param>
        /// <param name="timeout">
        /// <para>The maximum amount of time Service Fabric will allow this operation to continue before returning a TimeoutException.</para>
        /// </param>
        /// <param name="cancellationToken">
        /// <para>The <see cref="System.Threading.CancellationToken" /> that the operation is observing.  It can be used to send a notification that the
        /// operation should be canceled.  Note that cancellation is advisory and that the operation may still be completed even if it is canceled.</para>
        /// </param>
        /// <returns>
        /// <para>The task representing the asynchronous operation.</para>
        /// </returns>
        public Task RegisterServiceTypeAsync(string serviceTypeName, Type serviceTypeImplementation, TimeSpan timeout, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();

            bool isStateful = FabricRuntime.ValidateParametersForRegisterServiceType(serviceTypeName, serviceTypeImplementation);

            ServiceFactoryBroker factory = new ServiceFactoryBroker(new DefaultServiceFactory(serviceTypeImplementation), this.codePackageActivationContext);

            return(this.RegisterServiceFactoryAsyncHelper(isStateful, serviceTypeName, factory, (uint)timeout.TotalMilliseconds, cancellationToken));
        }