Example #1
0
        public void Scan(Assembly assembly)
        {
            bool postBuildNeeded;

            DependencyBuilder.Scan(assembly, out postBuildNeeded);

            if (postBuildNeeded)
            {
                DependencyBuilder.PostBuildScan(new List <Assembly>()
                {
                    assembly
                });
            }
        }
Example #2
0
        /// <summary>
        /// Registers all dependencies in referenced assemblies.
        /// </summary>
        /// <author>Anwar</author>
        /// <date>11/9/2011</date>

        public static void ScanAll()
        {
            var path = HostingEnvironment.IsHosted
                           ? HostingEnvironment.MapPath("~/App_Data/bindings.json")
                           : Path.Combine(Environment.CurrentDirectory, "bindings.json");

            if (File.Exists(path))
            {
                using (Stream stream = new FileStream(path, FileMode.Open))
                {
                    Container.LoadFrom(stream);
                    var assemblies = ActivationManager.Assemblies;


                    var list = new List <Assembly>();

                    foreach (var assembly in assemblies.AsParallel())
                    {
                        var attr = assembly.GetCustomAttribute <ContainerAssemblyAttribute>();

                        if (attr != null && attr.PostBuild)
                        {
                            list.Add(assembly);
                        }
                    }

                    DependencyBuilder.PostBuildScan(list);
                }
            }
            else
            {
                DependencyBuilder.ScanAll();
                using (Stream stream = new FileStream(path, FileMode.Create))
                {
                    Container.SaveTo(stream);
                }
            }
        }