Skip to content

Commit

Permalink
Its now possible to specify providers of assemblies - fixes #650
Browse files Browse the repository at this point in the history
  • Loading branch information
einari committed Jun 12, 2015
1 parent 21eb636 commit 7e1d6c5
Show file tree
Hide file tree
Showing 21 changed files with 300 additions and 375 deletions.
8 changes: 0 additions & 8 deletions Source/Bifrost.Specs/Bifrost.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,6 @@
<Compile Include="Execution\for_any_conventions\SelfBindingConvention.cs" />
<Compile Include="Execution\for_any_conventions\TypeWithSingletonAttribute.cs" />
<Compile Include="Execution\for_any_conventions\when_resolving_a_type_that_has_singleton_attribute.cs" />
<Compile Include="Execution\for_AssemblyProvider\FakeModule.cs" />
<Compile Include="Execution\for_AssemblyProvider\given\all_dependencies.cs" />
<Compile Include="Execution\for_AssemblyProvider\given\an_unitialized_assembly_provider.cs" />
<Compile Include="Execution\for_AssemblyProvider\FakeAssembly.cs" />
<Compile Include="Execution\for_AssemblyProvider\when_getting_assemblies_with_assembly_from_app_domain_that_should_filter_away.cs" />
<Compile Include="Execution\for_AssemblyProvider\when_getting_assemblies_with_dll_assembly_from_file_system_that_should_filter_away.cs" />
<Compile Include="Execution\for_AssemblyProvider\when_getting_assemblies_with_dll_assembly_from_file_system_that_should_not_filter_away.cs" />
<Compile Include="Execution\for_AssemblyProvider\when_getting_assemblies_with_assembly_from_app_domain_that_should_not_filter_away.cs" />
<Compile Include="Execution\for_BindingConventionManager\FakeBindingConvention.cs" />
<Compile Include="Execution\for_BindingConventionManager\given\a_binding_convention_manager.cs" />
<Compile Include="Execution\for_BindingConventionManager\given\a_binding_convention_manager_with_one_type.cs" />
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 5 additions & 2 deletions Source/Bifrost/Bifrost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
<Compile Include="Configuration\Assemblies\IncludeAll.cs" />
<Compile Include="Configuration\Assemblies\IncludeAllRule.cs" />
<Compile Include="Configuration\Assemblies\IncludeAllExtensions.cs" />
<Compile Include="Execution\AppDomainAssemblyProvider.cs" />
<Compile Include="Execution\AssemblyAdded.cs" />
<Compile Include="Execution\AssemblyInfo.cs" />
<Compile Include="Execution\AssemblySpecifiers.cs" />
<Compile Include="Configuration\CallContextConfiguration.cs" />
<Compile Include="Configuration\ConfigurationStorageElement.cs" />
Expand All @@ -139,6 +142,7 @@
<Compile Include="Configuration\ExecutionContextConfiguration.cs" />
<Compile Include="Configuration\FrontendConfiguration.cs" />
<Compile Include="Execution\DefaultAssemblySpecifier.cs" />
<Compile Include="Execution\FileSystemAssemblyProvider.cs" />
<Compile Include="Execution\IAssemblySpecifiers.cs" />
<Compile Include="Configuration\ICallContextConfiguration.cs" />
<Compile Include="Configuration\ICanConfigure.cs" />
Expand All @@ -159,13 +163,12 @@
<Compile Include="Execution\AssemblyFilters.cs" />
<Compile Include="Execution\AssemblyProvider.cs" />
<Compile Include="Execution\AssemblyUtility.cs" />
<Compile Include="Execution\ExecutionEnvironment.cs" />
<Compile Include="Execution\FileSystem.cs" />
<Compile Include="Execution\IAssemblyProvider.cs" />
<Compile Include="Execution\IAssemblyUtility.cs" />
<Compile Include="Execution\ICanProvideAssemblies.cs" />
<Compile Include="Execution\ICanSpecifyAssemblies.cs" />
<Compile Include="Execution\IAssemblyFilters.cs" />
<Compile Include="Execution\IExecutionEnvironment.cs" />
<Compile Include="Execution\IFileSystem.cs" />
<Compile Include="Execution\InvalidSignatureException.cs" />
<Compile Include="Execution\CannotInvokeMethodBecauseTargetIsNotAlive.cs" />
Expand Down
13 changes: 9 additions & 4 deletions Source/Bifrost/Configuration/Configure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class Configure : IConfigure
#if (SILVERLIGHT)
public static Configure DiscoverAndConfigure(Action<AssembliesConfigurationBuilder> assembliesConfigurationBuilderCallback=null)
#else
public static Configure DiscoverAndConfigure(Action<AssembliesConfigurationBuilder> assembliesConfigurationBuilderCallback = null, IExecutionEnvironment environment = null)
public static Configure DiscoverAndConfigure(Action<AssembliesConfigurationBuilder> assembliesConfigurationBuilderCallback = null, IEnumerable<ICanProvideAssemblies> additionalAssemblyProviders = null)
#endif
{
var assembliesConfigurationBuilder = BuildAssembliesConfigurationIfCallbackDefined(assembliesConfigurationBuilderCallback);
Expand All @@ -94,13 +94,18 @@ public static Configure DiscoverAndConfigure(Action<AssembliesConfigurationBuild
var assemblySpecifiers = new AssemblySpecifiers(new TypeFinder(), assembliesConfigurationBuilder.RuleBuilder);
assemblySpecifiers.SpecifyUsingSpecifiersFrom(Assembly.GetExecutingAssembly());

if( environment == null ) environment = new ExecutionEnvironment(new FileSystem());
var assemblyProviders = new List<ICanProvideAssemblies>
{
new AppDomainAssemblyProvider(),
new FileSystemAssemblyProvider(new FileSystem())
};

if (additionalAssemblyProviders != null) assemblyProviders.AddRange(additionalAssemblyProviders);

var assembliesConfiguration = new AssembliesConfiguration(assembliesConfigurationBuilder.RuleBuilder);
var assemblyProvider = new AssemblyProvider(
AppDomain.CurrentDomain,
assemblyProviders,
new AssemblyFilters(assembliesConfiguration),
environment,
new AssemblyUtility(),
assemblySpecifiers);
#endif
Expand Down
72 changes: 72 additions & 0 deletions Source/Bifrost/Execution/AppDomainAssemblyProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#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 System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

namespace Bifrost.Execution
{
/// <summary>
/// Represents an implementation of <see cref="ICanProvideAssemblies"/> that provides assemblies from the current <see cref="_AppDomain"/>
/// </summary>
public class AppDomainAssemblyProvider : ICanProvideAssemblies
{
/// <summary>
/// Initializes a new instance of <see cref="AppDomainAssemblyProvider"/>
/// </summary>
public AppDomainAssemblyProvider()
{
AppDomain.CurrentDomain.AssemblyLoad += AssemblyLoaded;

}

#pragma warning disable 1591 // Xml Comments
public event AssemblyAdded AssemblyAdded = (a) => { };

public IEnumerable<AssemblyInfo> AvailableAssemblies
{
get
{
return AppDomain.CurrentDomain.GetAssemblies()
.Where(assembly => !assembly.IsDynamic)
.Select(assembly =>
{
var name = assembly.GetName();
var assemblyInfo = new AssemblyInfo(name.Name, assembly.Location);
return assemblyInfo;
});
}
}

public _Assembly Get(AssemblyInfo assemblyInfo)
{
return AppDomain.CurrentDomain.GetAssemblies()
.Where(assembly =>
!assembly.IsDynamic &&
assembly.Location == assemblyInfo.Path).SingleOrDefault();
}
#pragma warning restore 1591 // Xml Comments

void AssemblyLoaded(object sender, AssemblyLoadEventArgs args)
{
AssemblyAdded(args.LoadedAssembly);
}
}
}
Loading

0 comments on commit 7e1d6c5

Please sign in to comment.