예제 #1
0
파일: Injector.cs 프로젝트: ChicK00o/suice
        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);
        }