コード例 #1
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            // Durable instancing could not be used with
            // singleton instancing.
            ServiceBehaviorAttribute serviceBehavior =
                serviceDescription.Behaviors.Find<ServiceBehaviorAttribute>();

            if (serviceBehavior != null &&
                serviceBehavior.InstanceContextMode == InstanceContextMode.Single)
            {
                throw new InvalidOperationException(
                    ResourceHelper.GetString("ExSingeltonInstancingNotSupported"));
            }

            // Use the StorageManagerFactory to create an instance of a
            // storage manager.
            IStorageManager storageManager =
                StorageManagerFactory.GetStorageManager(storageManagerType);

            InstanceContextInitializer contextInitializer =
                new InstanceContextInitializer(storageManager);

            InstanceProvider instanceProvider =
                new InstanceProvider(serviceDescription.ServiceType);

            foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher cd = cdb as ChannelDispatcher;

                if (cd != null)
                {
                    foreach (EndpointDispatcher ed in cd.Endpoints)
                    {
                        ed.DispatchRuntime.InstanceContextInitializers.Add(contextInitializer);
                        ed.DispatchRuntime.InstanceProvider = instanceProvider;
                    }
                }
            }
        }
コード例 #2
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            // Durable instancing could not be used with
            // singleton instancing.
            ServiceBehaviorAttribute serviceBehavior =
                serviceDescription.Behaviors.Find <ServiceBehaviorAttribute>();

            if (serviceBehavior != null &&
                serviceBehavior.InstanceContextMode == InstanceContextMode.Single)
            {
                throw new InvalidOperationException(
                          ResourceHelper.GetString("ExSingeltonInstancingNotSupported"));
            }

            // Use the StorageManagerFactory to create an instance of a
            // storage manager.
            IStorageManager storageManager =
                StorageManagerFactory.GetStorageManager(storageManagerType);

            InstanceContextInitializer contextInitializer =
                new InstanceContextInitializer(storageManager);

            InstanceProvider instanceProvider =
                new InstanceProvider(serviceDescription.ServiceType);

            foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher cd = cdb as ChannelDispatcher;

                if (cd != null)
                {
                    foreach (EndpointDispatcher ed in cd.Endpoints)
                    {
                        ed.DispatchRuntime.InstanceContextInitializers.Add(contextInitializer);
                        ed.DispatchRuntime.InstanceProvider = instanceProvider;
                    }
                }
            }
        }