Ejemplo n.º 1
0
        public void Register(Type type)
        {
            var con = type.GetCustomAttribute <ConfigurationAttribute>();

            if (con == null)
            {
                return;
            }

            if (con.Profile != null)
            {
                if (!_profileMatcher.Matches(con.Profile))
                {
                    return;
                }
            }

            var instance = _instanceFactory.CreateFor(type.GetTypeInfo());

            if (instance is IModule module)
            {
                _containerBuilder.RegisterModule(module);
            }

            foreach (var method in type.GetRuntimeMethods().Where(it => !it.IsStatic))
            {
                RegisterMethod(method, instance);
            }
        }
Ejemplo n.º 2
0
        public void Register(Type type)
        {
            var com = type.GetCustomAttribute <ComponentAttribute>();

            if (com == null)
            {
                return;
            }

            if (com.Profile != null)
            {
                if (!_profileMatcher.Matches(com.Profile))
                {
                    return;
                }
            }

            var isGeneric = type.IsGenericType;

            if (isGeneric)
            {
                _containerBuilder.RegisterGeneric(type)
                .ApplyDefault()
                .ApplyAsSelf(com)
                .ApplyAsImplementedInterfaces(com)
                .ApplyAs(type.GetCustomAttributes <AsAttribute>())
                .ApplyScope(type.GetCustomAttribute <ScopeAttribute>())
                .ApplyKeys(type.GetCustomAttributes <KeyAttribute>())
                .ApplyMetadata(type.GetCustomAttributes <MetadataAttribute>())
                .ApplyFeatures(type, _features)
                ;
                return;
            }

            _containerBuilder.RegisterType(type)
            .ApplyDefault()
            .ApplyAsSelf(com)
            .ApplyAsImplementedInterfaces(com)
            .ApplyAs(type.GetCustomAttributes <AsAttribute>())
            .ApplyScope(type.GetCustomAttribute <ScopeAttribute>())
            .ApplyKeys(type.GetCustomAttributes <KeyAttribute>())
            .ApplyMetadata(type.GetCustomAttributes <MetadataAttribute>())
            .ApplyFeatures(type, _features)
            ;
        }