예제 #1
0
        /// <summary>
        /// This is called when a module is discovered through reflection and it needs
        /// to be consutucted and initialized, or when a package is explicitly registered
        /// with a custom namespace
        /// </summary>
        private IPackage BuildPackage(IPackage package, Type type, Func <Type, object> factory, string namespaceName)
        {
            if (package == null && factory != null && typeof(IPackage).IsAssignableFrom(type))
            {
                package = factory(type) as IPackage;
            }

            var packageDefinition = BuildUpPackage(package, type);

            package = packageDefinition.Build();

            if (!string.IsNullOrEmpty(namespaceName))
            {
                package.NamespaceName = namespaceName;
            }

            var packageBuilder = new FluentBuilder(
                this,
                package,
                _dataCatalog,
                _dataDependencyFactory,
                _dataSupplierFactory);

            package.Build(packageBuilder);

            return(package);
        }
        /// <summary>
        /// This is called when a package is discovered through reflection and it needs
        /// to be consutucted and initialized, or when a package is explicitly registered
        /// with a custom namespace
        /// </summary>
        private IPackage BuildPackage(IPackage package, Type type, Func <Type, object> factory, string namespaceName)
        {
            if (_debugLogging)
            {
                var message = "Fluent builder is building";

                if (package != null)
                {
                    message += " an instance of package " + package.GetType().DisplayName();
                    if (type != null)
                    {
                        message += " using attributes from " + type.DisplayName();
                    }
                }
                else
                {
                    if (type == null)
                    {
                        message += " a package of unspecified type";
                    }
                    else
                    {
                        message += " a package of type " + type.DisplayName();
                    }

                    if (factory == null)
                    {
                        message += " using the default public constructor";
                    }
                    else
                    {
                        message += " using a factory";
                    }
                }

                if (!string.IsNullOrEmpty(namespaceName))
                {
                    message += " defining the '" + namespaceName + "' namespace";
                }

                Trace.WriteLine(message);
            }

            if (package == null && factory != null && typeof(IPackage).IsAssignableFrom(type))
            {
                package = factory(type) as IPackage;
            }

            var packageDefinition = BuildUpPackage(package, type, factory);

            package = packageDefinition.Build();

            if (!string.IsNullOrEmpty(namespaceName))
            {
                package.NamespaceName = namespaceName;
            }

            var packageBuilder = new FluentBuilder(
                this,
                factory,
                package,
                _dataCatalog,
                _dataDependencyFactory,
                _dataSupplierFactory);

            package.Build(packageBuilder);

            return(package);
        }