protected virtual void InitializeConfiguration(string assemblyDirectory)
        {
            ApplicationAssemblyLoaderFilter filter = ApplicationAssemblyLoaderFilter.Instance;

            // TODO: Duplicates logic from AssemblyFinder? The DLL searching part below can probably be removed.
            List <Assembly> assemblies = new List <Assembly>();
            DirectoryInfo   dir        = new DirectoryInfo(assemblyDirectory);

            foreach (FileInfo file in dir.GetFiles("*.dll"))
            {
                Assembly asm = Assembly.LoadFile(file.FullName);
                if (filter.ShouldConsiderAssembly(asm.GetName()) && filter.ShouldIncludeAssembly(asm))
                {
                    assemblies.Add(asm);
                }
            }
            DomainObjectsConfiguration.SetCurrent(
                new FakeDomainObjectsConfiguration(DomainObjectsConfiguration.Current.MappingLoader, GetPersistenceConfiguration(), new QueryConfiguration()));

            var rootAssemblyFinder = new FixedRootAssemblyFinder(assemblies.Select(a => new RootAssembly(a, false)).ToArray());

            var assemblyLoader = new FilteringAssemblyLoader(filter);
            ITypeDiscoveryService typeDiscoveryService =
                new AssemblyFinderTypeDiscoveryService(new AssemblyFinder(rootAssemblyFinder, assemblyLoader));

            var mappingReflector       = new MappingReflector(typeDiscoveryService);
            var persistenceModelLoader =
                new PersistenceModelLoader(new StorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage));
            var mappingConfiguration = new MappingConfiguration(mappingReflector, persistenceModelLoader);

            MappingConfiguration.SetCurrent(mappingConfiguration);
        }
        public void ApplicationAssemblyInclusion_DependsOnAttribute()
        {
            string compiledAssemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NonApplicationMarkedAssembly.dll");

            try
            {
                AppDomainRunner.Run(
                    delegate(object[] args)
                {
                    var path = (string)args[0];

                    ApplicationAssemblyLoaderFilter filter = ApplicationAssemblyLoaderFilter.Instance;
                    Assert.That(filter.ShouldIncludeAssembly(typeof(AttributeAssemblyLoaderFilterTest).Assembly), Is.True);
                    Assert.That(filter.ShouldIncludeAssembly(typeof(TestFixtureAttribute).Assembly), Is.True);
                    Assert.That(filter.ShouldIncludeAssembly(typeof(ApplicationAssemblyLoaderFilter).Assembly), Is.True);
                    Assert.That(filter.ShouldIncludeAssembly(typeof(object).Assembly), Is.True);
                    Assert.That(filter.ShouldIncludeAssembly(typeof(Uri).Assembly), Is.True);

                    var assemblyCompiler = new AssemblyCompiler(@"Reflection\TypeDiscovery\TestAssemblies\NonApplicationMarkedAssembly", path,
                                                                typeof(NonApplicationAssemblyAttribute).Assembly.Location);
                    assemblyCompiler.Compile();
                    Assert.That(filter.ShouldIncludeAssembly(assemblyCompiler.CompiledAssembly), Is.False);
                }, compiledAssemblyPath);
            }
            finally
            {
                if (File.Exists(compiledAssemblyPath))
                {
                    FileUtility.DeleteAndWaitForCompletion(compiledAssemblyPath);
                }
            }
        }