Esempio n. 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);
        }
Esempio n. 2
0
        private void CreateDynamicProvider(Type type, out Provider provider)
        {
            Type          providedType  = type.GetGenericArguments()[0];
            ImplementedBy implementedBy = providedType.GetTypeAttribute <ImplementedBy>();

            Type implementedType = (implementedBy == null)
                ? providedType
                : implementedBy.ImplementedType;

            Type dynamicProviderType = typeof(DynamicProvider <>).MakeGenericType(providedType);

            providersMap.Add(type, provider = (Provider)dynamicProviderType.New(
                                 providedType,
                                 implementedType,
                                 GetDependencyTypes(implementedType)
                                 ));
        }