Exemplo n.º 1
0
        public IContainer RegisterAll <T>()
        {
            Type[] components;

            if (TypeDiscovery.Discover <T>(out components))
            {
                components.ForEach(c => RegisterAsTransient <T>(c));
            }
            return(this);
        }
Exemplo n.º 2
0
        private IEnumerable <ConfigurationEntry> LoadCatalogue()
        {
            Type[] items;

            TypeDiscovery.Discover <ISupportConfigurationDiscovery>(out items);

            return(items.Select(i =>
            {
                var target = (ISupportConfigurationDiscovery)Activator.CreateInstance(i);
                return target.GetConfigurationMetadata();
            }).ToList());
        }
Exemplo n.º 3
0
        public bool Load(out TI[] components)
        {
            components = new TI[0];
            Type[] matchingTypes;

            if (!TypeDiscovery.Discover <TI>(out matchingTypes))
            {
                return(false);
            }

            var candidates = from type in matchingTypes
                             select(TI) Activator.CreateInstance(type);

            components = candidates.ToArray();
            return(components.Length > 0);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="profile"></param>
        /// <returns></returns>
        public bool Load(string name, out IRoleProfile profile)
        {
            profile = null;
            Type[] matchingTypes;

            if (!TypeDiscovery.Discover <IRoleProfile>(out matchingTypes))
            {
                return(false);
            }

            var profileTypeName = (name.EndsWith("Profile")) ? name : name + "Profile";
            var profileType     = matchingTypes.First(candidateType => string.Compare(candidateType.Name, profileTypeName) == 0);

            profile = (IRoleProfile)Activator.CreateInstance(profileType);
            return(profile != null);
        }
Exemplo n.º 5
0
        protected virtual void FindAndExecuteBootstrappers(Type configType, object config)
        {
            var bootstrapBuilderType      = typeof(ISupportBootStrapping <>);
            var bootstrapperInterfaceType = bootstrapBuilderType.MakeGenericType(configType);

            Type[] bootstrapperTypes;
            if (!TypeDiscovery.Discover(bootstrapperInterfaceType, out bootstrapperTypes))
            {
                return;
            }

            // found some...
            foreach (var bootstrapperType in bootstrapperTypes)
            {
                dynamic bootstrapper = Activator.CreateInstance(bootstrapperType);
                bootstrapperInterfaceType.GetMethod("Execute")
                .Invoke(bootstrapper, new[] { config });
            }
        }
Exemplo n.º 6
0
        public IContainer RegisterAllWithInterception <T, TI>()
        {
            Type[] components;

            if (!TypeDiscovery.Discover <T>(out components))
            {
                return(this);
            }

            var interceptorTypes = (from iType in ResolveAll <TI>()
                                    select iType.GetType()).ToArray();

            components.ToList().ForEach(c =>
                                        Instance.Register(Component.For(typeof(T))
                                                          .LifeStyle.Transient
                                                          .ImplementedBy(c)
                                                          .Interceptors(interceptorTypes)));
            return(this);
        }
Exemplo n.º 7
0
        public bool Load(out TI[] components)
        {
            components = new TI[0];
            Type[] matchingTypes;

            if (!TypeDiscovery.Discover <TI>(out matchingTypes))
            {
                return(false);
            }

            var candidates = from type in matchingTypes
                             select(TI) Activator.CreateInstance(type)
                             into instance
                             select instance;

            var plugins = candidates.Cast <IPlugin>()
                          .InitialisePlugins();

            components = plugins.Cast <TI>().ToArray();
            return(components.Length > 0);
        }
Exemplo n.º 8
0
        private static bool GetType <T>(string targetTypeName, out Type targetType)
        {
            targetType = null;
            Type[] matchingTypes;

            if (!TypeDiscovery.Discover <T>(t => t.Name.Equals(targetTypeName,
                                                               StringComparison.OrdinalIgnoreCase), out matchingTypes))
            {
                return(false);
            }

            if (matchingTypes.Count() != 1)
            {
                throw new InvalidOperationException(string.Format("Searching for type '{0}' named '{1}'; found {2} matches, expected only 1",
                                                                  typeof(T).Name,
                                                                  targetTypeName,
                                                                  matchingTypes.Count()));
            }

            targetType = matchingTypes.First();
            return(true);
        }
Exemplo n.º 9
0
 public void TheTypeDiscoveryIsExecuted()
 {
     TypeDiscovery.Discover(_typeToDiscover, out _typesFound);
 }