Exemplo n.º 1
0
        private void EnsureIsInitializedCore()
        {
            // Only pass locals byref because InvokerUtil may store temporary results in the byref.
            // If two threads both reference this.count, temporary results may interact.
            InvokeDelegate invokeDelegate = InvokerUtil.GenerateInvokeDelegate(Method, out int inputParameterCount, out int outputParameterCount);

            _outputParameterCount = outputParameterCount;
            _inputParameterCount  = inputParameterCount;
            _invokeDelegate       = invokeDelegate; // must set this last due to race
        }
Exemplo n.º 2
0
 private void EnsureIsInitialized()
 {
     if (this.invokeDelegate == null)
     {
         // Only pass locals byref because InvokerUtil may store temporary results in the byref.
         // If two threads both reference this.count, temporary results may interact.
         int            inputParameterCount;
         int            outputParameterCount;
         InvokeDelegate invokeDelegate = new InvokerUtil().GenerateInvokeDelegate(taskMethod, out inputParameterCount, out outputParameterCount);
         this.inputParameterCount  = inputParameterCount;
         this.outputParameterCount = outputParameterCount;
         this.invokeDelegate       = invokeDelegate; // must set this last due to race
     }
 }
Exemplo n.º 3
0
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            this.immutableRuntime = immutableRuntime;
            initializers          = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers);

            provider  = dispatch.InstanceProvider;
            singleton = dispatch.SingletonInstanceContext;
            //    this.transactionAutoCompleteOnSessionClose = dispatch.TransactionAutoCompleteOnSessionClose;
            //    this.releaseServiceInstanceOnTransactionComplete = dispatch.ReleaseServiceInstanceOnTransactionComplete;
            isSynchronized          = (dispatch.ConcurrencyMode != ConcurrencyMode.Multiple);
            instanceContextProvider = dispatch.InstanceContextProvider;

            if (provider == null)
            {
                ConstructorInfo constructor = null;
                if (dispatch.Type != null)
                {
                    constructor = InstanceBehavior.GetConstructor(dispatch.Type);
                }

                if (singleton == null)
                {
                    if (dispatch.Type != null && (dispatch.Type.GetTypeInfo().IsAbstract || dispatch.Type.GetTypeInfo().IsInterface))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxServiceTypeNotCreatable));
                    }

                    if (constructor == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor));
                    }
                }

                if (constructor != null)
                {
                    if (singleton == null || !singleton.IsWellKnown)
                    {
                        InvokerUtil            util    = new InvokerUtil();
                        CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor);
                        provider = new InstanceProvider(creator);
                    }
                }
            }

            if (singleton != null)
            {
                singleton.Behavior = this;
            }
        }
Exemplo n.º 4
0
        internal InstanceBehavior(DispatchRuntime dispatch, ImmutableDispatchRuntime immutableRuntime)
        {
            _immutableRuntime = immutableRuntime;
            _initializers     = EmptyArray <IInstanceContextInitializer> .ToArray(dispatch.InstanceContextInitializers);

            _provider  = dispatch.InstanceProvider;
            _singleton = dispatch.SingletonInstanceContext;
            InstanceContextProvider = dispatch.InstanceContextProvider;

            if (_provider == null)
            {
                ConstructorInfo constructor = null;
                if (dispatch.Type != null)
                {
                    constructor = GetConstructor(dispatch.Type);
                }

                if (_singleton == null)
                {
                    if (dispatch.Type != null && (dispatch.Type.GetTypeInfo().IsAbstract || dispatch.Type.GetTypeInfo().IsInterface))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxServiceTypeNotCreatable));
                    }

                    if (constructor == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor));
                    }
                }

                if (constructor != null)
                {
                    if (_singleton == null || !_singleton.IsWellKnown)
                    {
                        InvokerUtil            util    = new InvokerUtil();
                        CreateInstanceDelegate creator = util.GenerateCreateInstanceDelegate(dispatch.Type, constructor);
                        _provider = new InstanceProvider(creator);
                    }
                }
            }

            if (_singleton != null)
            {
                _singleton.Behavior = this;
            }
        }