diff --git a/Source/Bifrost.Autofac/AssemblySpecifier.cs b/Source/Bifrost.Autofac/AssemblySpecifier.cs deleted file mode 100644 index 47854821d..000000000 --- a/Source/Bifrost.Autofac/AssemblySpecifier.cs +++ /dev/null @@ -1,38 +0,0 @@ -#region License -// -// Copyright (c) 2008-2015, Dolittle (http://www.dolittle.com) -// -// Licensed under the MIT License (http://opensource.org/licenses/MIT) -// -// You may not use this file except in compliance with the License. -// You may obtain a copy of the license at -// -// http://github.com/dolittle/Bifrost/blob/master/MIT-LICENSE.txt -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#endregion -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.Autofac -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "Autofac" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.Autofac/Bifrost.Autofac.csproj b/Source/Bifrost.Autofac/Bifrost.Autofac.csproj index 478c635bb..ed37ea0c5 100644 --- a/Source/Bifrost.Autofac/Bifrost.Autofac.csproj +++ b/Source/Bifrost.Autofac/Bifrost.Autofac.csproj @@ -55,7 +55,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.Client/AssemblySpecifier.cs b/Source/Bifrost.Client/AssemblySpecifier.cs deleted file mode 100644 index d7c279797..000000000 --- a/Source/Bifrost.Client/AssemblySpecifier.cs +++ /dev/null @@ -1,28 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "Presentation", - "vshost", - "WindowsBase", - "UIAutomation", - "Castle.Core" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.Client/Bifrost.Client.csproj b/Source/Bifrost.Client/Bifrost.Client.csproj index 363952e69..3d7528805 100644 --- a/Source/Bifrost.Client/Bifrost.Client.csproj +++ b/Source/Bifrost.Client/Bifrost.Client.csproj @@ -15,7 +15,7 @@ true - + true full false @@ -62,7 +62,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.RavenDB/AssemblySpecifier.cs b/Source/Bifrost.Default/AssemblySpecifier.cs similarity index 55% rename from Source/Bifrost.RavenDB/AssemblySpecifier.cs rename to Source/Bifrost.Default/AssemblySpecifier.cs index d04e08a57..a148f0f61 100644 --- a/Source/Bifrost.RavenDB/AssemblySpecifier.cs +++ b/Source/Bifrost.Default/AssemblySpecifier.cs @@ -2,23 +2,17 @@ * Copyright (c) 2008-2017 Dolittle. All rights reserved. * Licensed under the MIT License. See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------*/ + using Bifrost.Configuration.Assemblies; using Bifrost.Execution; -namespace Bifrost.RavenDB +namespace Web { - /// - /// Reperesents an assembly specifier for client aspects - /// public class AssemblySpecifier : ICanSpecifyAssemblies { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) + public void Specify(IAssembliesConfiguration configuration) { - builder.ExcludeAssembliesStartingWith( - "Raven" - ); + configuration.IncludeAssembliesStartingWith("Web.dll"); } -#pragma warning disable 1591 // Xml Comments } } diff --git a/Source/Bifrost.Default/Bifrost.Default.csproj b/Source/Bifrost.Default/Bifrost.Default.csproj index a9173b7f3..9e6e38a5d 100644 --- a/Source/Bifrost.Default/Bifrost.Default.csproj +++ b/Source/Bifrost.Default/Bifrost.Default.csproj @@ -77,6 +77,7 @@ Properties\CommonAssemblyInfo.cs + diff --git a/Source/Bifrost.EntityFramework/AssemblySpecifier.cs b/Source/Bifrost.EntityFramework/AssemblySpecifier.cs deleted file mode 100644 index 3929cd04b..000000000 --- a/Source/Bifrost.EntityFramework/AssemblySpecifier.cs +++ /dev/null @@ -1,24 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.EntityFramework -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "EntityFramework" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.EntityFramework/Bifrost.EntityFramework.csproj b/Source/Bifrost.EntityFramework/Bifrost.EntityFramework.csproj index 8336c15e2..87004be52 100644 --- a/Source/Bifrost.EntityFramework/Bifrost.EntityFramework.csproj +++ b/Source/Bifrost.EntityFramework/Bifrost.EntityFramework.csproj @@ -49,7 +49,6 @@ - diff --git a/Source/Bifrost.FluentValidation/AssemblySpecifier.cs b/Source/Bifrost.FluentValidation/AssemblySpecifier.cs deleted file mode 100644 index 42347834d..000000000 --- a/Source/Bifrost.FluentValidation/AssemblySpecifier.cs +++ /dev/null @@ -1,24 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.FluentValidation -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "FluentValidation" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.FluentValidation/Bifrost.FluentValidation.csproj b/Source/Bifrost.FluentValidation/Bifrost.FluentValidation.csproj index 759166e80..e42c43401 100644 --- a/Source/Bifrost.FluentValidation/Bifrost.FluentValidation.csproj +++ b/Source/Bifrost.FluentValidation/Bifrost.FluentValidation.csproj @@ -49,7 +49,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.JSON/AssemblySpecifier.cs b/Source/Bifrost.JSON/AssemblySpecifier.cs deleted file mode 100644 index 191e260a2..000000000 --- a/Source/Bifrost.JSON/AssemblySpecifier.cs +++ /dev/null @@ -1,24 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.JSON -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "Newtonsoft.Json" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.JSON/Bifrost.JSON.csproj b/Source/Bifrost.JSON/Bifrost.JSON.csproj index 0105d2361..67798e8c6 100644 --- a/Source/Bifrost.JSON/Bifrost.JSON.csproj +++ b/Source/Bifrost.JSON/Bifrost.JSON.csproj @@ -48,7 +48,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.MongoDb/Bifrost.MongoDB.csproj b/Source/Bifrost.MongoDb/Bifrost.MongoDB.csproj index 6e19a63fb..0a3904bfd 100644 --- a/Source/Bifrost.MongoDb/Bifrost.MongoDB.csproj +++ b/Source/Bifrost.MongoDb/Bifrost.MongoDB.csproj @@ -52,7 +52,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.NHibernate/AssemblySpecifier.cs b/Source/Bifrost.NHibernate/AssemblySpecifier.cs deleted file mode 100644 index 175429fdc..000000000 --- a/Source/Bifrost.NHibernate/AssemblySpecifier.cs +++ /dev/null @@ -1,26 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.NHibernate -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "FluentNHibernate", - "Iesi.Collections", - "NHibernate" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.NHibernate/Bifrost.NHibernate.csproj b/Source/Bifrost.NHibernate/Bifrost.NHibernate.csproj index b30e2b41a..d84896aa2 100644 --- a/Source/Bifrost.NHibernate/Bifrost.NHibernate.csproj +++ b/Source/Bifrost.NHibernate/Bifrost.NHibernate.csproj @@ -52,7 +52,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.Ninject/AssemblySpecifier.cs b/Source/Bifrost.Ninject/AssemblySpecifier.cs deleted file mode 100644 index c409261e0..000000000 --- a/Source/Bifrost.Ninject/AssemblySpecifier.cs +++ /dev/null @@ -1,24 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.Ninject -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "Ninject" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.Ninject/Bifrost.Ninject.csproj b/Source/Bifrost.Ninject/Bifrost.Ninject.csproj index 1b1fc9a68..83cc29f06 100644 --- a/Source/Bifrost.Ninject/Bifrost.Ninject.csproj +++ b/Source/Bifrost.Ninject/Bifrost.Ninject.csproj @@ -52,7 +52,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.QuickStart.WPF/App.xaml.cs b/Source/Bifrost.QuickStart.WPF/App.xaml.cs index 9f5119646..dce669315 100644 --- a/Source/Bifrost.QuickStart.WPF/App.xaml.cs +++ b/Source/Bifrost.QuickStart.WPF/App.xaml.cs @@ -1,6 +1,5 @@ using System.Windows; using Bifrost.Configuration; -using Bifrost.Configuration.Assemblies; namespace Bifrost.QuickStart.WPF { @@ -11,7 +10,7 @@ public partial class App : Application { static App() { - Configure.DiscoverAndConfigure(a => a.IncludeAll()); //.ExceptAssembliesStartingWith("System","Microsoft","mscor","FluentValidation","Ninject")); + Configure.DiscoverAndConfigure(); } } } diff --git a/Source/Bifrost.MongoDb/AssemblySpecifier.cs b/Source/Bifrost.QuickStart/AssemblySpecifier.cs similarity index 55% rename from Source/Bifrost.MongoDb/AssemblySpecifier.cs rename to Source/Bifrost.QuickStart/AssemblySpecifier.cs index 22a959f13..a148f0f61 100644 --- a/Source/Bifrost.MongoDb/AssemblySpecifier.cs +++ b/Source/Bifrost.QuickStart/AssemblySpecifier.cs @@ -2,23 +2,17 @@ * Copyright (c) 2008-2017 Dolittle. All rights reserved. * Licensed under the MIT License. See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------*/ + using Bifrost.Configuration.Assemblies; using Bifrost.Execution; -namespace Bifrost.MongoDB +namespace Web { - /// - /// Reperesents an assembly specifier for client aspects - /// public class AssemblySpecifier : ICanSpecifyAssemblies { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) + public void Specify(IAssembliesConfiguration configuration) { - builder.ExcludeAssembliesStartingWith( - "MongoDB" - ); + configuration.IncludeAssembliesStartingWith("Web.dll"); } -#pragma warning disable 1591 // Xml Comments } } diff --git a/Source/Bifrost.QuickStart/Bifrost.QuickStart.csproj b/Source/Bifrost.QuickStart/Bifrost.QuickStart.csproj index 585a7d2a9..48d1b5cd4 100644 --- a/Source/Bifrost.QuickStart/Bifrost.QuickStart.csproj +++ b/Source/Bifrost.QuickStart/Bifrost.QuickStart.csproj @@ -169,6 +169,7 @@ + diff --git a/Source/Bifrost.RavenDB/Bifrost.RavenDB.csproj b/Source/Bifrost.RavenDB/Bifrost.RavenDB.csproj index 969fc116d..a9a5f3293 100644 --- a/Source/Bifrost.RavenDB/Bifrost.RavenDB.csproj +++ b/Source/Bifrost.RavenDB/Bifrost.RavenDB.csproj @@ -51,7 +51,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.SimpleInjector/AssemblySpecifier.cs b/Source/Bifrost.SimpleInjector/AssemblySpecifier.cs deleted file mode 100644 index 8566eec2b..000000000 --- a/Source/Bifrost.SimpleInjector/AssemblySpecifier.cs +++ /dev/null @@ -1,24 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.SimpleInjector -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "SimpleInjector" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.SimpleInjector/Bifrost.SimpleInjector.csproj b/Source/Bifrost.SimpleInjector/Bifrost.SimpleInjector.csproj index 30e434648..d4bb1ea68 100644 --- a/Source/Bifrost.SimpleInjector/Bifrost.SimpleInjector.csproj +++ b/Source/Bifrost.SimpleInjector/Bifrost.SimpleInjector.csproj @@ -49,7 +49,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.Specs/Configuration/for_Configure/given/a_configure_instance.cs b/Source/Bifrost.Specs/Configuration/for_Configure/given/a_configure_instance.cs index 3762e01ba..85099b2e2 100644 --- a/Source/Bifrost.Specs/Configuration/for_Configure/given/a_configure_instance.cs +++ b/Source/Bifrost.Specs/Configuration/for_Configure/given/a_configure_instance.cs @@ -73,7 +73,7 @@ public class a_configure_instance type_importer_mock = new Mock(); container_mock.Setup(c => c.Get()).Returns(type_importer_mock.Object); - configure_instance = Configure.With(container_mock.Object, default_conventions_mock.Object, default_bindings_mock.Object, new AssembliesConfiguration(null)); + configure_instance = Configure.With(container_mock.Object, default_conventions_mock.Object, default_bindings_mock.Object, Mock.Of()); configurators_mock = new Mock>(); configurators_mock.Setup(c => c.GetEnumerator()).Returns(new List().GetEnumerator()); diff --git a/Source/Bifrost.StructureMap/AssemblySpecifier.cs b/Source/Bifrost.StructureMap/AssemblySpecifier.cs deleted file mode 100644 index 6d5efe69b..000000000 --- a/Source/Bifrost.StructureMap/AssemblySpecifier.cs +++ /dev/null @@ -1,24 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.StructureMap -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "StructureMap" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.StructureMap/Bifrost.StructureMap.csproj b/Source/Bifrost.StructureMap/Bifrost.StructureMap.csproj index 93286f4d3..c922f7627 100644 --- a/Source/Bifrost.StructureMap/Bifrost.StructureMap.csproj +++ b/Source/Bifrost.StructureMap/Bifrost.StructureMap.csproj @@ -45,7 +45,6 @@ Properties\CommonAssemblyInfo.cs - diff --git a/Source/Bifrost.Web/AssemblySpecifier.cs b/Source/Bifrost.Web/AssemblySpecifier.cs deleted file mode 100644 index 41d0ad976..000000000 --- a/Source/Bifrost.Web/AssemblySpecifier.cs +++ /dev/null @@ -1,25 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; -using Bifrost.Execution; - -namespace Bifrost.Web -{ - /// - /// Reperesents an assembly specifier for client aspects - /// - public class AssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "Owin", - "WebActivator" - ); - } -#pragma warning disable 1591 // Xml Comments - } -} diff --git a/Source/Bifrost.Web/Bifrost.Web.csproj b/Source/Bifrost.Web/Bifrost.Web.csproj index 85c4eee5b..f14a83a53 100644 --- a/Source/Bifrost.Web/Bifrost.Web.csproj +++ b/Source/Bifrost.Web/Bifrost.Web.csproj @@ -55,7 +55,6 @@ - diff --git a/Source/Bifrost/AssemblySpecifier.cs b/Source/Bifrost/AssemblySpecifier.cs index 604345fa2..e0d5ce3a9 100644 --- a/Source/Bifrost/AssemblySpecifier.cs +++ b/Source/Bifrost/AssemblySpecifier.cs @@ -8,18 +8,14 @@ namespace Bifrost { /// - /// Reperesents an assembly specifier for client aspects + /// Represents an assembly specifier for client aspects. /// public class AssemblySpecifier : ICanSpecifyAssemblies { #pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) + public void Specify(IAssembliesConfiguration configuration) { - builder.ExcludeAssembliesStartingWith( - "System", - "mscorlib", - "Microsoft" - ); + configuration.IncludeAssembliesStartingWith("Bifrost"); } #pragma warning disable 1591 // Xml Comments } diff --git a/Source/Bifrost/Bifrost.csproj b/Source/Bifrost/Bifrost.csproj index 535cb4051..2be076624 100644 --- a/Source/Bifrost/Bifrost.csproj +++ b/Source/Bifrost/Bifrost.csproj @@ -54,6 +54,9 @@ Properties\CommonAssemblyInfo.cs + + + @@ -125,17 +128,12 @@ - - - - - - - - + + + @@ -144,7 +142,6 @@ - diff --git a/Source/Bifrost/Configuration/Assemblies/AssembliesConfiguration.cs b/Source/Bifrost/Configuration/Assemblies/AssembliesConfiguration.cs deleted file mode 100644 index 5d8f1bc28..000000000 --- a/Source/Bifrost/Configuration/Assemblies/AssembliesConfiguration.cs +++ /dev/null @@ -1,30 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Specifications; - -namespace Bifrost.Configuration.Assemblies -{ - /// - /// Represents the configuration for Assemblies - /// - public class AssembliesConfiguration - { - IAssemblyRuleBuilder _assemblyRuleBuilder; - - /// - /// Initializes a new instance of - /// - /// that builds the rules - public AssembliesConfiguration(IAssemblyRuleBuilder assemblyRuleBuilder) - { - _assemblyRuleBuilder = assemblyRuleBuilder; - } - - /// - /// Gets the specification used to specifying which assemblies to include - /// - public Specification Specification { get { return _assemblyRuleBuilder.Specification; } } - } -} diff --git a/Source/Bifrost/Configuration/Assemblies/AssembliesConfigurationBuilder.cs b/Source/Bifrost/Configuration/Assemblies/AssembliesConfigurationBuilder.cs deleted file mode 100644 index 03a7ff7fb..000000000 --- a/Source/Bifrost/Configuration/Assemblies/AssembliesConfigurationBuilder.cs +++ /dev/null @@ -1,31 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -namespace Bifrost.Configuration.Assemblies -{ - /// - /// Represents a builder for building configuration used by - /// - public class AssembliesConfigurationBuilder - { - /// - /// Gets the rule builder used - /// - public IAssemblyRuleBuilder RuleBuilder { get; private set; } - - - /// - /// Include all assemblies with possible exceptions - /// - /// - /// Returns the configuration object for the rule - /// - public IncludeAll IncludeAll() - { - var includeAll = new IncludeAll(); - RuleBuilder = includeAll; - return includeAll; - } - } -} diff --git a/Source/Bifrost/Configuration/Assemblies/AssembliesStartingWith.cs b/Source/Bifrost/Configuration/Assemblies/AssembliesStartingWith.cs new file mode 100644 index 000000000..98faba2d3 --- /dev/null +++ b/Source/Bifrost/Configuration/Assemblies/AssembliesStartingWith.cs @@ -0,0 +1,21 @@ +using System.Linq; +using Bifrost.Specifications; + +namespace Bifrost.Configuration.Assemblies +{ + /// + /// Rule representing an addition to , + /// that includes assemblies in files starting with any of the given names. + /// + public class AssembliesStartingWith : Specification + { + /// + /// Initializes an instance of . + /// + /// List of assembly name prefixes. + public AssembliesStartingWith(params string[] names) + { + Predicate = a => names.Any(a.StartsWith); + } + } +} diff --git a/Source/Bifrost/Configuration/Assemblies/AssemblyConfigurationExtensions.cs b/Source/Bifrost/Configuration/Assemblies/AssemblyConfigurationExtensions.cs new file mode 100644 index 000000000..7585d7c3d --- /dev/null +++ b/Source/Bifrost/Configuration/Assemblies/AssemblyConfigurationExtensions.cs @@ -0,0 +1,40 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) 2008-2017 Dolittle. All rights reserved. + * Licensed under the MIT License. See LICENSE in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +using Bifrost.Specifications; + +namespace Bifrost.Configuration.Assemblies +{ + /// + /// Provides extensions for . + /// + public static class AssemblyConfigurationExtensions + { + /// + /// Includes specified assemblies. + /// + /// to build upon. + /// Names that assemblies should be starting with. + /// Chained + public static IAssembliesConfiguration IncludeAssembliesStartingWith( + this IAssembliesConfiguration assembliesConfiguration, params string[] names) + { + assembliesConfiguration.Specification = assembliesConfiguration.Specification.Or(new AssembliesStartingWith(names)); + return assembliesConfiguration; + } + + /// + /// Excludes specified assemblies. + /// + /// to build upon. + /// Names that assemblies should not be starting with. + /// Chained + public static IAssembliesConfiguration ExcludeAssembliesStartingWith( + this IAssembliesConfiguration assembliesConfiguration, params string[] names) + { + assembliesConfiguration.Specification = assembliesConfiguration.Specification.AndNot(new AssembliesStartingWith(names)); + return assembliesConfiguration; + } + } +} diff --git a/Source/Bifrost/Configuration/Assemblies/AssemblyRuleBuilderExtensions.cs b/Source/Bifrost/Configuration/Assemblies/AssemblyRuleBuilderExtensions.cs deleted file mode 100644 index 941588803..000000000 --- a/Source/Bifrost/Configuration/Assemblies/AssemblyRuleBuilderExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Specifications; - -namespace Bifrost.Configuration.Assemblies -{ - /// - /// Provides extensions for - /// - public static class AssemblyRuleBuilderExtensions - { - - /// - /// Excludes specified assemblies - /// - /// to build upon - /// Names that assemblies should not be starting with - /// Chained - public static IAssemblyRuleBuilder ExcludeAssembliesStartingWith(this IAssemblyRuleBuilder assemblyBuilder, params string[] names) - { - assemblyBuilder.Specification = assemblyBuilder.Specification.And(new ExceptAssembliesStartingWith(names)); - return assemblyBuilder; - } - } -} diff --git a/Source/Bifrost/Configuration/Assemblies/ExceptAssembliesStartingWith.cs b/Source/Bifrost/Configuration/Assemblies/ExceptAssembliesStartingWith.cs deleted file mode 100644 index c2fba0ded..000000000 --- a/Source/Bifrost/Configuration/Assemblies/ExceptAssembliesStartingWith.cs +++ /dev/null @@ -1,25 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using System.Linq; -using Bifrost.Specifications; - -namespace Bifrost.Configuration.Assemblies -{ - /// - /// Rule representing an exception for , - /// excluding assembies starting with - /// - public class ExceptAssembliesStartingWith : Specification - { - /// - /// Initializes an instance of - /// - /// - public ExceptAssembliesStartingWith(params string[] names) - { - Predicate = a => !names.Any(n => a.StartsWith(n)); - } - } -} diff --git a/Source/Bifrost/Configuration/Assemblies/IAssemblyRuleBuilder.cs b/Source/Bifrost/Configuration/Assemblies/IAssembliesConfiguration.cs similarity index 73% rename from Source/Bifrost/Configuration/Assemblies/IAssemblyRuleBuilder.cs rename to Source/Bifrost/Configuration/Assemblies/IAssembliesConfiguration.cs index c6f19a3be..b7859ea27 100644 --- a/Source/Bifrost/Configuration/Assemblies/IAssemblyRuleBuilder.cs +++ b/Source/Bifrost/Configuration/Assemblies/IAssembliesConfiguration.cs @@ -7,13 +7,12 @@ namespace Bifrost.Configuration.Assemblies { /// - /// Defines a rule builder for building configuration for assemblies and how to include - /// or exclude assemblies + /// Defines a configuration for how to include or exclude assemblies. /// - public interface IAssemblyRuleBuilder + public interface IAssembliesConfiguration { /// - /// Get the specification to use + /// Get the specification to use. /// Specification Specification { get; set; } } diff --git a/Source/Bifrost/Configuration/Assemblies/IncludeAll.cs b/Source/Bifrost/Configuration/Assemblies/IncludeAll.cs deleted file mode 100644 index 73bdbb5b7..000000000 --- a/Source/Bifrost/Configuration/Assemblies/IncludeAll.cs +++ /dev/null @@ -1,28 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Specifications; - -namespace Bifrost.Configuration.Assemblies -{ - /// - /// Represents the builder for building the and - /// possible exceptions - /// - public class IncludeAll : IAssemblyRuleBuilder - { - /// - /// Initializes an instance of - /// - public IncludeAll() - { - Specification = new IncludeAllRule(); - } - - /// - /// Gets the - /// - public Specification Specification { get; set; } - } -} diff --git a/Source/Bifrost/Configuration/Assemblies/IncludeAllExtensions.cs b/Source/Bifrost/Configuration/Assemblies/IncludeAllExtensions.cs deleted file mode 100644 index eee7d8fad..000000000 --- a/Source/Bifrost/Configuration/Assemblies/IncludeAllExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Extensions; -using Bifrost.Specifications; - -namespace Bifrost.Configuration.Assemblies -{ - /// - /// Extensions for - /// - public static class IncludeAllExtensions - { - /// - /// Include all except for assemblies that has a name starting with the given name - /// - /// Configuration object - /// Names of assemblies to exclude - /// Chain of configuration object - public static IncludeAll ExceptAssembliesStartingWith(this IncludeAll includeAll, params string[] assemblyNames) - { - var specification = includeAll.Specification; - assemblyNames.ForEach(assemblyName => specification = specification.And(new ExceptAssembliesStartingWith(assemblyName))); - includeAll.Specification = specification; - return includeAll; - } - } -} diff --git a/Source/Bifrost/Configuration/Assemblies/IncludeAllRule.cs b/Source/Bifrost/Configuration/Assemblies/IncludeAllRule.cs deleted file mode 100644 index 83329b0bb..000000000 --- a/Source/Bifrost/Configuration/Assemblies/IncludeAllRule.cs +++ /dev/null @@ -1,23 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Specifications; - -namespace Bifrost.Configuration.Assemblies -{ - /// - /// Represents a rule specific to assemblies - /// and used for the - /// - public class IncludeAllRule : Specification - { - /// - /// Initializes an instance of - /// - public IncludeAllRule() - { - Predicate = a => true; - } - } -} diff --git a/Source/Bifrost/Configuration/Assemblies/IncludeNone.cs b/Source/Bifrost/Configuration/Assemblies/IncludeNone.cs new file mode 100644 index 000000000..2ea5389cc --- /dev/null +++ b/Source/Bifrost/Configuration/Assemblies/IncludeNone.cs @@ -0,0 +1,23 @@ +using Bifrost.Specifications; + +namespace Bifrost.Configuration.Assemblies +{ + /// + /// Represents the for building the . + /// + public class IncludeNone : IAssembliesConfiguration + { + /// + /// Initializes an instance of . + /// + public IncludeNone() + { + Specification = new IncludeNoneRule(); + } + + /// + /// Gets the . + /// + public Specification Specification { get; set; } + } +} diff --git a/Source/Bifrost/Configuration/Assemblies/IncludeNoneRule.cs b/Source/Bifrost/Configuration/Assemblies/IncludeNoneRule.cs new file mode 100644 index 000000000..ab2f4d123 --- /dev/null +++ b/Source/Bifrost/Configuration/Assemblies/IncludeNoneRule.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using Bifrost.Specifications; + +namespace Bifrost.Configuration.Assemblies +{ + /// + /// Represents a rule specific to assemblies + /// that matches no assemblies. + /// + public class IncludeNoneRule : Specification + { + /// + /// Initializes an instance of . + /// + public IncludeNoneRule() + { + Predicate = a => false; + } + } +} diff --git a/Source/Bifrost/Configuration/Configure.cs b/Source/Bifrost/Configuration/Configure.cs index ebe92fb91..3379f7746 100644 --- a/Source/Bifrost/Configuration/Configure.cs +++ b/Source/Bifrost/Configuration/Configure.cs @@ -28,12 +28,16 @@ public class Configure : IConfigure /// public static Configure Instance { get; private set; } - - Configure(IContainer container, BindingLifecycle defaultLifecycle, IDefaultConventions defaultConventions, IDefaultBindings defaultBindings, AssembliesConfiguration assembliesConfiguration) + Configure( + IContainer container, + BindingLifecycle defaultLifecycle, + IDefaultConventions defaultConventions, + IDefaultBindings defaultBindings, + IAssembliesConfiguration assembliesConfiguration) { SystemName = "[Not Set]"; - AssembliesConfiguration = assembliesConfiguration; + Assemblies = assembliesConfiguration; container.DefaultLifecycle = defaultLifecycle; container.Bind(this); @@ -50,30 +54,31 @@ public class Configure : IConfigure /// Configure by letting Bifrost discover anything that implements the discoverable configuration interfaces /// /// - public static Configure DiscoverAndConfigure(Action assembliesConfigurationBuilderCallback = null, IEnumerable additionalAssemblyProviders = null) + public static Configure DiscoverAndConfigure( + IAssembliesConfiguration assembliesConfiguration = null, + IEnumerable additionalAssemblyProviders = null) { - IContractToImplementorsMap contractToImplementorsMap; - var assembliesConfigurationBuilder = BuildAssembliesConfigurationIfCallbackDefined(assembliesConfigurationBuilderCallback); - - contractToImplementorsMap = new ContractToImplementorsMap(); - var executingAssembly = typeof(Configure).GetTypeInfo().Assembly; - contractToImplementorsMap.Feed(executingAssembly.GetTypes()); - var assemblySpecifiers = new AssemblySpecifiers(contractToImplementorsMap, new TypeFinder(), assembliesConfigurationBuilder.RuleBuilder); - assemblySpecifiers.SpecifyUsingSpecifiersFrom(executingAssembly); - var assemblyProviders = new List { #if(NET461) new AppDomainAssemblyProvider(), #endif - //new DefaultAssemblyProvider() - new FileSystemAssemblyProvider(new FileSystem()) + //new DefaultAssemblyProvider(), + new FileSystemAssemblyProvider(new FileSystem()), }; + if (additionalAssemblyProviders != null) + { + assemblyProviders.AddRange(additionalAssemblyProviders); + } - if (additionalAssemblyProviders != null) assemblyProviders.AddRange(additionalAssemblyProviders); + assembliesConfiguration = assembliesConfiguration ?? new IncludeNone(); + var assemblySpecifiers = new AssemblySpecifiers(assembliesConfiguration); + var executingAssembly = typeof(Configure).GetTypeInfo().Assembly; - var assembliesConfiguration = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder); + IContractToImplementorsMap contractToImplementorsMap = new ContractToImplementorsMap(); + contractToImplementorsMap.Feed(executingAssembly.GetTypes()); + assemblySpecifiers.SpecifyUsingSpecifiersFrom(executingAssembly); var assemblyProvider = new AssemblyProvider( assemblyProviders, new AssemblyFilters(assembliesConfiguration), @@ -98,13 +103,22 @@ public static Configure DiscoverAndConfigure(Action and the Lifecycle of objects set to none /// /// to configure with - /// to use + /// to use /// to use for providing assemblies /// for keeping track of the relationship between contracts and implementors /// Configuration object to continue configuration on - public static Configure With(IContainer container, AssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider, IContractToImplementorsMap contractToImplementorsMap) + public static Configure With( + IContainer container, + IAssembliesConfiguration assembliesConfiguration, + IAssemblyProvider assemblyProvider, + IContractToImplementorsMap contractToImplementorsMap) { - return With(container, BindingLifecycle.Transient, assembliesConfiguration, assemblyProvider, contractToImplementorsMap); + return With( + container, + BindingLifecycle.Transient, + assembliesConfiguration, + assemblyProvider, + contractToImplementorsMap); } /// @@ -112,13 +126,22 @@ public static Configure With(IContainer container, AssembliesConfiguration assem /// /// to configure with /// Default for object creation/management - /// to use + /// to use /// to use for providing assemblies /// for keeping track of the relationship between contracts and implementors /// Configuration object to continue configuration on - public static Configure With(IContainer container, BindingLifecycle defaultObjectLifecycle, AssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider, IContractToImplementorsMap contractToImplementorsMap) + public static Configure With( + IContainer container, + BindingLifecycle defaultObjectLifecycle, + IAssembliesConfiguration assembliesConfiguration, + IAssemblyProvider assemblyProvider, + IContractToImplementorsMap contractToImplementorsMap) { - return With(container, defaultObjectLifecycle, new DefaultConventions(container), new DefaultBindings(assembliesConfiguration, assemblyProvider, contractToImplementorsMap), assembliesConfiguration); + return With( + container, + defaultObjectLifecycle, + new DefaultConventions(container), + new DefaultBindings(assembliesConfiguration, assemblyProvider, contractToImplementorsMap), assembliesConfiguration); } /// @@ -136,14 +159,22 @@ public static void Reset() /// to configure with /// to use /// to use - /// to use + /// to use /// - public static Configure With(IContainer container, IDefaultConventions defaultConventions, IDefaultBindings defaultBindings, AssembliesConfiguration assembliesConfiguration) + public static Configure With( + IContainer container, + IDefaultConventions defaultConventions, + IDefaultBindings defaultBindings, + IAssembliesConfiguration assembliesConfiguration) { - return With(container, BindingLifecycle.Transient, defaultConventions, defaultBindings, assembliesConfiguration); + return With( + container, + BindingLifecycle.Transient, + defaultConventions, + defaultBindings, + assembliesConfiguration); } - /// /// Configure with a specific , and /// @@ -151,9 +182,14 @@ public static Configure With(IContainer container, IDefaultConventions defaultCo /// Default for object creation/management /// to use /// to use - /// to use + /// to use /// - public static Configure With(IContainer container, BindingLifecycle defaultObjectLifecycle, IDefaultConventions defaultConventions, IDefaultBindings defaultBindings, AssembliesConfiguration assembliesConfiguration) + public static Configure With( + IContainer container, + BindingLifecycle defaultObjectLifecycle, + IDefaultConventions defaultConventions, + IDefaultBindings defaultBindings, + IAssembliesConfiguration assembliesConfiguration) { if (Instance == null) { @@ -170,7 +206,6 @@ public static Configure With(IContainer container, BindingLifecycle defaultObjec public IContainer Container { get; private set; } public string SystemName { get; set; } public Assembly EntryAssembly { get; private set; } - public AssembliesConfiguration AssembliesConfiguration { get; private set; } public IDefaultStorageConfiguration DefaultStorage { get; set; } public ICommandsConfiguration Commands { get; private set; } public IEventsConfiguration Events { get; private set; } @@ -183,7 +218,7 @@ public static Configure With(IContainer container, BindingLifecycle defaultObjec public ICallContextConfiguration CallContext { get; private set; } public IExecutionContextConfiguration ExecutionContext { get; private set; } public ISecurityConfiguration Security { get; private set; } - public AssembliesConfiguration Assemblies { get; private set; } + public IAssembliesConfiguration Assemblies { get; private set; } public IQualityAssurance QualityAssurance { get; private set; } public CultureInfo Culture { get; set; } public CultureInfo UICulture { get; set; } @@ -276,15 +311,6 @@ static Type DiscoverCanCreateContainerType(IEnumerable assemblies) return createContainerType; } - static AssembliesConfigurationBuilder BuildAssembliesConfigurationIfCallbackDefined(Action assembliesConfigurationBuilderCallback) - { - var builder = new AssembliesConfigurationBuilder(); - if (assembliesConfigurationBuilderCallback != null) assembliesConfigurationBuilderCallback(builder); - if (builder.RuleBuilder == null) builder.IncludeAll(); - return builder; - } - - static void ThrowIfAmbiguousMatchFoundForCanCreateContainer(Type createContainerType) { if (createContainerType != null) diff --git a/Source/Bifrost/Configuration/Defaults/DefaultBindings.cs b/Source/Bifrost/Configuration/Defaults/DefaultBindings.cs index 7a73c7203..8ad10d141 100644 --- a/Source/Bifrost/Configuration/Defaults/DefaultBindings.cs +++ b/Source/Bifrost/Configuration/Defaults/DefaultBindings.cs @@ -12,14 +12,14 @@ namespace Bifrost.Configuration.Defaults /// public class DefaultBindings : IDefaultBindings { - AssembliesConfiguration _assembliesConfiguration; - IAssemblyProvider _assemblyProvider; - IContractToImplementorsMap _contractToImplentorsMap; + readonly IAssembliesConfiguration _assembliesConfiguration; + readonly IAssemblyProvider _assemblyProvider; + readonly IContractToImplementorsMap _contractToImplentorsMap; /// /// Initializes a new instance of /// - public DefaultBindings(AssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider, IContractToImplementorsMap contractToImplentorsMap) + public DefaultBindings(IAssembliesConfiguration assembliesConfiguration, IAssemblyProvider assemblyProvider, IContractToImplementorsMap contractToImplentorsMap) { _assembliesConfiguration = assembliesConfiguration; _assemblyProvider = assemblyProvider; @@ -31,7 +31,7 @@ public void Initialize(IContainer container) { container.Bind(container); container.Bind(_contractToImplentorsMap); - container.Bind(_assembliesConfiguration); + container.Bind(_assembliesConfiguration); container.Bind(_assemblyProvider); container.Bind(typeof(global::Bifrost.Execution.Assemblies), BindingLifecycle.Singleton); container.Bind(typeof(TypeDiscoverer), BindingLifecycle.Singleton); diff --git a/Source/Bifrost/Configuration/IConfigure.cs b/Source/Bifrost/Configuration/IConfigure.cs index 0bdec900d..cec6ebaaf 100644 --- a/Source/Bifrost/Configuration/IConfigure.cs +++ b/Source/Bifrost/Configuration/IConfigure.cs @@ -95,7 +95,7 @@ public interface IConfigure /// /// Gets the configuration for assemblies and how they are treated /// - AssembliesConfiguration Assemblies { get; } + IAssembliesConfiguration Assemblies { get; } /// /// Gets or sets the culture to use in Bifrost diff --git a/Source/Bifrost/Execution/AppDomainAssemblyProvider.cs b/Source/Bifrost/Execution/AppDomainAssemblyProvider.cs index 70acbee43..b05adbaed 100644 --- a/Source/Bifrost/Execution/AppDomainAssemblyProvider.cs +++ b/Source/Bifrost/Execution/AppDomainAssemblyProvider.cs @@ -2,6 +2,7 @@ * Copyright (c) 2008-2017 Dolittle. All rights reserved. * Licensed under the MIT License. See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------*/ + using System; using System.Collections.Generic; using System.Linq; @@ -11,49 +12,55 @@ namespace Bifrost.Execution { /// - /// Represents an implementation of that provides assemblies from the current + /// Represents an implementation of that provides assemblies from the current . /// public class AppDomainAssemblyProvider : ICanProvideAssemblies { + private readonly IDictionary _loadedAssemblies; + /// - /// Initializes a new instance of + /// Initializes a new instance of . /// public AppDomainAssemblyProvider() { AppDomain.CurrentDomain.AssemblyLoad += AssemblyLoaded; + _loadedAssemblies = BuildAssemblyMap(); } -#pragma warning disable 1591 // Xml Comments - public event AssemblyAdded AssemblyAdded = (a) => { }; - - public IEnumerable AvailableAssemblies + private void AssemblyLoaded(object sender, AssemblyLoadEventArgs args) { - get + var assembly = args.LoadedAssembly; + if (!assembly.IsDynamic) { - return AppDomain.CurrentDomain.GetAssemblies() - .Where(assembly => !assembly.IsDynamic) - .Select(assembly => - { - var name = assembly.GetName(); - var assemblyInfo = new AssemblyInfo(name.Name, assembly.Location); - return assemblyInfo; - }); + _loadedAssemblies[AssemblyInfoFromAssembly(assembly)] = assembly; + AssemblyAdded(assembly); } } - public Assembly Get(AssemblyInfo assemblyInfo) + private static IDictionary BuildAssemblyMap() { - return AppDomain.CurrentDomain.GetAssemblies() - .Where(assembly => - !assembly.IsDynamic && - assembly.GetName().Name == assemblyInfo.Name).SingleOrDefault(); + return AppDomain.CurrentDomain + .GetAssemblies() + .Where(a => !a.IsDynamic) + .ToDictionary(AssemblyInfoFromAssembly, a => a); } -#pragma warning restore 1591 // Xml Comments - void AssemblyLoaded(object sender, AssemblyLoadEventArgs args) + private static AssemblyInfo AssemblyInfoFromAssembly(Assembly assembly) { + return new AssemblyInfo(assembly.GetName().Name, assembly.Location); + } - AssemblyAdded(args.LoadedAssembly); +#pragma warning disable 1591 // Xml Comments + public event AssemblyAdded AssemblyAdded = a => { }; + + public IEnumerable AvailableAssemblies => _loadedAssemblies.Keys; + + public Assembly Get(AssemblyInfo assemblyInfo) + { + Assembly assembly; + _loadedAssemblies.TryGetValue(assemblyInfo, out assembly); + return assembly; } +#pragma warning restore 1591 // Xml Comments } -} +} \ No newline at end of file diff --git a/Source/Bifrost/Execution/AssemblyFilters.cs b/Source/Bifrost/Execution/AssemblyFilters.cs index 9b8a1eaf4..c6213d20b 100644 --- a/Source/Bifrost/Execution/AssemblyFilters.cs +++ b/Source/Bifrost/Execution/AssemblyFilters.cs @@ -11,13 +11,13 @@ namespace Bifrost.Execution /// public class AssemblyFilters : IAssemblyFilters { - AssembliesConfiguration _assembliesConfiguration; + readonly IAssembliesConfiguration _assembliesConfiguration; /// /// Initializes an instance of /// /// - public AssemblyFilters(AssembliesConfiguration assembliesConfiguration) + public AssemblyFilters(IAssembliesConfiguration assembliesConfiguration) { _assembliesConfiguration = assembliesConfiguration; } diff --git a/Source/Bifrost/Execution/AssemblyProvider.cs b/Source/Bifrost/Execution/AssemblyProvider.cs index a08ec21c7..90b32017c 100644 --- a/Source/Bifrost/Execution/AssemblyProvider.cs +++ b/Source/Bifrost/Execution/AssemblyProvider.cs @@ -67,61 +67,59 @@ void HookUpAssemblyAddedForProviders() void AssemblyLoaded(Assembly assembly) { - if (_assemblyUtility.IsAssemblyDynamic(assembly)) return; + if (_assemblyUtility.IsAssemblyDynamic(assembly)) + { + return; + } - var assemblyFile = new FileInfo(assembly.Location); - if (!_assemblyFilters.ShouldInclude(assemblyFile.Name)) return; + var newSpecifiers = _assemblySpecifiers.SpecifyUsingSpecifiersFrom(assembly); AddAssembly(assembly); + if (newSpecifiers) + { + RecalculateAssemblies(); + } } void Populate() { - foreach (var provider in _assemblyProviders) - { - var assembliesToInclude = provider.AvailableAssemblies.Where( - a => - _assemblyFilters.ShouldInclude(a.FileName) && - _assemblyUtility.IsAssembly(a) - ); - assembliesToInclude.Select(provider.Get).ForEach(AddAssembly); - } + var assemblies = AvailableAssemblies(); + assemblies.ForEach(a => _assemblySpecifiers.SpecifyUsingSpecifiersFrom(a)); + assemblies.ForEach(AddAssembly); } - void SpecifyRules(Assembly assembly) + IList AvailableAssemblies() { - _assemblySpecifiers.SpecifyUsingSpecifiersFrom(assembly); + return _assemblyProviders + .SelectMany(p => p.AvailableAssemblies, (provider, assemblyInfo) => new {provider, assemblyInfo}) + .GroupBy(pair => pair.assemblyInfo.Name) + .Select(group => group.First()) + .Where(pair => _assemblyUtility.IsAssembly(pair.assemblyInfo)) + .Select(pair => pair.provider.Get(pair.assemblyInfo)) + .Where(assembly => !assembly.IsDynamic) + .ToList(); } - void ReapplyFilter() + bool ShouldInclude(Assembly assembly) { - var assembliesToRemove = _assemblies.Where(a => !_assemblyFilters.ShouldInclude(a.GetName().Name)).ToArray(); - assembliesToRemove.ForEach((a) =>_assemblies.Remove(a)); + return _assemblyFilters.ShouldInclude(new FileInfo(assembly.Location).Name); } void AddAssembly(Assembly assembly) { lock (_lockObject) { - if (!_assemblies.Contains(assembly, comparer) && - !_assemblyUtility.IsAssemblyDynamic(assembly)) + if (!_assemblies.Contains(assembly, comparer) && ShouldInclude(assembly)) { _assemblies.Add(assembly); - - if (assembly.FullName.Contains("Web")) - { - var i = 0; - i++; - } _contractToImplementorsMap.Feed(assembly.GetTypes()); - SpecifyRules(assembly); - ReapplyFilter(); } } } - bool Matches(AssemblyName a, AssemblyName b) + void RecalculateAssemblies() { - return a.ToString() == b.ToString(); + var assemblies = AvailableAssemblies(); + assemblies.ForEach(AddAssembly); } } } diff --git a/Source/Bifrost/Execution/AssemblySpecificationException.cs b/Source/Bifrost/Execution/AssemblySpecificationException.cs new file mode 100644 index 000000000..6ef105f7a --- /dev/null +++ b/Source/Bifrost/Execution/AssemblySpecificationException.cs @@ -0,0 +1,34 @@ +using System; + +namespace Bifrost.Execution +{ + /// + /// The exception that is thrown when specification of assemblies fails. + /// + public class AssemblySpecificationException : Exception + { + /// + /// Initializes an instance of . + /// + public AssemblySpecificationException() + { + } + + /// + /// Initializes an instance of . + /// + /// Message with details about the exception. + public AssemblySpecificationException(string message) : base(message) + { + } + + /// + /// Initializes an instance of . + /// + /// Message with details about the exception. + /// The exception that caused this exception. + public AssemblySpecificationException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/Source/Bifrost/Execution/AssemblySpecifiers.cs b/Source/Bifrost/Execution/AssemblySpecifiers.cs index b1c058087..80997148c 100644 --- a/Source/Bifrost/Execution/AssemblySpecifiers.cs +++ b/Source/Bifrost/Execution/AssemblySpecifiers.cs @@ -3,6 +3,7 @@ * Licensed under the MIT License. See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------*/ using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using Bifrost.Configuration.Assemblies; @@ -15,35 +16,82 @@ namespace Bifrost.Execution /// public class AssemblySpecifiers : IAssemblySpecifiers { - ITypeFinder _typeFinder; - IContractToImplementorsMap _contractToImplementorsMap; - IAssemblyRuleBuilder _assemblyRuleBuilder; + static readonly object LockObject = new object(); + + readonly IAssembliesConfiguration _assembliesConfiguration; + readonly ISet _specifiedAssemblies; /// /// Initializes a new instance of /// - /// for keeping track of the relationship between contracts and implementors - /// to use for finding types - /// used for building the rules for assemblies - public AssemblySpecifiers(IContractToImplementorsMap contractToImplementorsMap, ITypeFinder typeFinder, IAssemblyRuleBuilder assemblyRuleBuilder) + public AssemblySpecifiers(IAssembliesConfiguration assembliesConfiguration) { - _typeFinder = typeFinder; - _assemblyRuleBuilder = assemblyRuleBuilder; - _contractToImplementorsMap = contractToImplementorsMap; + _assembliesConfiguration = assembliesConfiguration; + _specifiedAssemblies = new HashSet(); } #pragma warning disable 1591 // Xml Comments - public void SpecifyUsingSpecifiersFrom(Assembly assembly) + public bool SpecifyUsingSpecifiersFrom(Assembly assembly) { - _typeFinder - .FindMultiple(_contractToImplementorsMap) - .Where(t => t.GetTypeInfo().Assembly.FullName == assembly.FullName) - .Where(type => type.HasDefaultConstructor()) - .ForEach(type => + lock (LockObject) + { + if (_specifiedAssemblies.Contains(assembly.FullName)) + { + return false; + } + + _specifiedAssemblies.Add(assembly.FullName); + + var specified = false; + if (MayReferenceICanSpecifyAssemblies(assembly)) { - var specifier = Activator.CreateInstance(type) as ICanSpecifyAssemblies; - specifier.Specify(_assemblyRuleBuilder); - }); + try + { + specified = assembly + .GetTypes() + .Where(t => t.GetTypeInfo().GetInterfaces().Contains(typeof(ICanSpecifyAssemblies))) + .Select(SpecifyFrom) + .ToList() + .Count > 0; + } + catch (ReflectionTypeLoadException e) + { + throw new AssemblySpecificationException( + $"Error while reflecting on the types of {assembly.FullName}. Loader exceptions encountered:\n" + + string.Join("\n", e.LoaderExceptions.Select(l => l.Message).Distinct())); + } + } + + return specified; + } + } + + ICanSpecifyAssemblies SpecifyFrom(Type type) + { + try + { + var specifier = Activator.CreateInstance(type) as ICanSpecifyAssemblies; + specifier.Specify(_assembliesConfiguration); + return specifier; + } + catch (MissingMethodException) + { + throw new AssemblySpecificationException( + $"Could not create instance of type {type.FullName}. It must have a default constructor."); + } + catch (Exception e) + { + throw new AssemblySpecificationException( + $"Error while specifying assemblies from {type.FullName}: {e.Message}", + e); + } + } + + static bool MayReferenceICanSpecifyAssemblies(Assembly assembly) + { + return + assembly.FullName.Contains("Bifrost") || + assembly.GetReferencedAssemblies().Any(a => a.FullName.Contains("Bifrost")); } #pragma warning restore 1591 // Xml Comments } diff --git a/Source/Bifrost/Execution/DefaultAssemblySpecifier.cs b/Source/Bifrost/Execution/DefaultAssemblySpecifier.cs deleted file mode 100644 index 424260d64..000000000 --- a/Source/Bifrost/Execution/DefaultAssemblySpecifier.cs +++ /dev/null @@ -1,25 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) 2008-2017 Dolittle. All rights reserved. - * Licensed under the MIT License. See LICENSE in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -using Bifrost.Configuration.Assemblies; - -namespace Bifrost.Execution -{ - /// - /// Represents a default assembly specifier - /// - public class DefaultAssemblySpecifier : ICanSpecifyAssemblies - { -#pragma warning disable 1591 // Xml Comments - public void Specify(IAssemblyRuleBuilder builder) - { - builder.ExcludeAssembliesStartingWith( - "System", - "mscorlib", - "Microsoft" - ); - } -#pragma warning restore 1591 // Xml Comments - } -} diff --git a/Source/Bifrost/Execution/IAssemblySpecifiers.cs b/Source/Bifrost/Execution/IAssemblySpecifiers.cs index acdcb363b..bac9df4e2 100644 --- a/Source/Bifrost/Execution/IAssemblySpecifiers.cs +++ b/Source/Bifrost/Execution/IAssemblySpecifiers.cs @@ -12,9 +12,10 @@ namespace Bifrost.Execution public interface IAssemblySpecifiers { /// - /// Specifies using specifiers found in a specific + /// Specifies using specifiers found in a specific /// - /// to find specifiers from - void SpecifyUsingSpecifiersFrom(Assembly assembly); + /// to find specifiers from + /// Whether any new specifiers was found in the assembly. + bool SpecifyUsingSpecifiersFrom(Assembly assembly); } } diff --git a/Source/Bifrost/Execution/ICanSpecifyAssemblies.cs b/Source/Bifrost/Execution/ICanSpecifyAssemblies.cs index ba84f7e88..cf2eb52fd 100644 --- a/Source/Bifrost/Execution/ICanSpecifyAssemblies.cs +++ b/Source/Bifrost/Execution/ICanSpecifyAssemblies.cs @@ -8,7 +8,7 @@ namespace Bifrost.Execution { /// - /// Specifies what assemblies to include + /// Specifies what assemblies to include or not. /// /// /// Typically used by implementations of to @@ -21,9 +21,9 @@ namespace Bifrost.Execution public interface ICanSpecifyAssemblies : IConvention { /// - /// Method that gets called for specifying which assemblies to include or not + /// Method that gets called for specifying which assemblies to include or not. /// - /// object to build specification on - void Specify(IAssemblyRuleBuilder builder); + /// object to build specification on. + void Specify(IAssembliesConfiguration configuration); } }