Ejemplo n.º 1
0
        private object GetInstance(ServiceRegistration svcReg)
        {
            object instance = null;

            if (svcReg.Instance == null)
            {
                if (svcReg.Callback != null)
                {
                    instance = svcReg.Callback(this, svcReg.ServiceType);
                }
                else
                {
                    instance = Activator.CreateInstance(svcReg.ServiceType);
                }

                if (svcReg.Scope == Scope.Singleton)
                {
                    svcReg.Instance = instance;
                }
            }
            else // Instance != null
            {
                if (svcReg.Scope == Scope.PerCall)
                {
                    var cloneable    = svcReg.Instance as ICloneable;
                    var comCloneable = svcReg.Instance as Jacobi.Vst3.Interop.ICloneable;

                    if (cloneable != null)
                    {
                        instance = cloneable.Clone();
                    }
                    else if (comCloneable != null)
                    {
                        instance = comCloneable.Clone();
                    }
                    else
                    {
                        throw new InvalidOperationException("Cannot clone Service instance for PerCall service request.");
                        //instance = svcReg.Instance;
                    }
                }
                else
                {
                    instance = svcReg.Instance;
                }
            }

            return(instance);
        }