示例#1
0
        private bool AttemptRegisterBinding(Type type)
        {
            ImplementedBy implementedBy = type.GetTypeAttribute<ImplementedBy>();
            bool success = implementedBy != null;

            if (success) {
                Type bindedType = implementedBy.ImplementedType;
                Singleton singletonAttribute = bindedType.GetTypeAttribute<Singleton>();
                Provider provider;

                if (!bindedType.GetInterfaces().Contains(type)) {
                    throw new InvalidImplementedByException(type.FullName, bindedType.FullName);
                }

                if (singletonAttribute != null) {
                    provider = new SingletonProvider(singletonAttribute.Scope, type, bindedType, GetDependencyTypes(bindedType));
                } else {
                    provider = new NoScopeProvider(type, bindedType, GetDependencyTypes(bindedType));
                }

                RegisterProvider(type, provider);
            }

            return success;
        }
示例#2
0
        private bool AttemptRegisterBinding(Type type)
        {
            ImplementedBy implementedBy = type.GetTypeAttribute <ImplementedBy>();
            bool          success       = implementedBy != null;

            if (success)
            {
                Type      bindedType         = implementedBy.ImplementedType;
                Singleton singletonAttribute = bindedType.GetTypeAttribute <Singleton>();
                Provider  provider;

                if (!bindedType.GetInterfaces().Contains(type))
                {
                    throw new InvalidImplementedByException(type.FullName, bindedType.FullName);
                }

                if (singletonAttribute != null)
                {
                    provider = new SingletonProvider(singletonAttribute.Scope, type, bindedType, GetDependencyTypes(bindedType));
                }
                else
                {
                    provider = new NoScopeProvider(type, bindedType, GetDependencyTypes(bindedType));
                }

                RegisterProvider(type, provider);
            }

            return(success);
        }