Skip to content

Commit

Permalink
Merge pull request #5 from dbones/master
Browse files Browse the repository at this point in the history
0,3 Changes
  • Loading branch information
dbones committed Oct 7, 2013
2 parents cb6960e + fa97a7a commit aebf88f
Show file tree
Hide file tree
Showing 56 changed files with 1,747 additions and 733 deletions.
59 changes: 40 additions & 19 deletions src/Boxes.Integration/Boxes.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,62 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContainerSetup\IRegister.cs" />
<Compile Include="ContainerSetup\Register.cs" />
<Compile Include="ContainerSetup\RegisterContext.cs" />
<Compile Include="ContainerSetup\TypeExtensions.cs" />
<Compile Include="Extensions\ISetupBoxesExtension.cs" />
<Compile Include="Extensions\IBoxesExtensionWithSetup.cs" />
<Compile Include="Factories\IIocSetup.cs" />
<Compile Include="InternalIoc\IInternalContainer.cs" />
<Compile Include="InternalIoc\Registration.cs" />
<Compile Include="InternalContainerExtensions.cs" />
<Compile Include="InternalIoc\InternalInternalContainer.cs" />
<Compile Include="Setup\Filters\DefaultTypeRegistrationFilter.cs" />
<Compile Include="Setup\IRegistrationTaskMapper.cs" />
<Compile Include="Setup\DefaultContainerSetup.cs" />
<Compile Include="Exceptions\ServiceTypeDoesNotMatchInstanceException.cs" />
<Compile Include="Exceptions\FailedTrustException.cs" />
<Compile Include="Trust\Contexts\BoxesExtensions\AssemblyFromPackageTrustContext.cs" />
<Compile Include="Trust\Contexts\BoxesExtensions\SetupFromPackageTrustContext.cs" />
<Compile Include="TypeExtensions.cs" />
<Compile Include="Setup\Registrations\IRegister.cs" />
<Compile Include="Setup\Registrations\RegisterBase.cs" />
<Compile Include="Setup\Registrations\RegisterContext.cs" />
<Compile Include="Setup\RegistrationContext.cs" />
<Compile Include="Exceptions\CreateLoaderException.cs" />
<Compile Include="Factories\FuncCreateLoader.cs" />
<Compile Include="Factories\ICreateLoader.cs" />
<Compile Include="Factories\IDependencyResolverFactory.cs" />
<Compile Include="Factories\IIocFactory.cs" />
<Compile Include="Factories\LoaderFactory.cs" />
<Compile Include="ObjectExtensions.cs" />
<Compile Include="Process\TopologicalProcessOrder.cs" />
<Compile Include="Process\TopologicalSortExtensions.cs" />
<Compile Include="Setup\BoxesIntergrationSetup.cs" />
<Compile Include="Setup\BoxesSetup.cs" />
<Compile Include="BoxesWrapperBase.cs" />
<Compile Include="Extensions\IBoxesExtension.cs" />
<Compile Include="Setup\IBoxesIntegrationSetup.cs" />
<Compile Include="IBoxesWrapper.cs" />
<Compile Include="ExtensionManifest.cs" />
<Compile Include="Setup\IPackageTypesFilter.cs" />
<Compile Include="Setup\Filters\ITypeRegistrationFilter.cs" />
<Compile Include="Process\IProcessOrder.cs" />
<Compile Include="Tasks\ExtendBoxesTask.cs" />
<Compile Include="Tasks\BootupPackageTask.cs" />
<Compile Include="ProcessPackageContext.cs" />
<Compile Include="Tasks\PipelineExecutorWrapper.cs" />
<Compile Include="Tasks\RegisterTypesWithIocPackageTask.cs" />
<Compile Include="ContainerSetup\BoxesContainerSetupBase.cs" />
<Compile Include="ContainerSetup\IBoxesContainerSetup.cs" />
<Compile Include="Extensions\IPackageBootup.cs" />
<Compile Include="Extensions\IPackageSetup.cs" />
<Compile Include="Setup\ContainerSetupBase.cs" />
<Compile Include="Setup\IContainerSetup.cs" />
<Compile Include="IDependencyResolver.cs" />
<Compile Include="LoaderProxy.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tasks\RunOnceBoxesTask.cs" />
<Compile Include="ContainerSetup\Contracts.cs" />
<Compile Include="ContainerSetup\Registration.cs" />
<Compile Include="ContainerSetup\RegistrationMeta.cs" />
<Compile Include="Tasks\SetupPackageTask.cs" />
<Compile Include="Setup\Registrations\Contracts.cs" />
<Compile Include="Setup\Registrations\Registration.cs" />
<Compile Include="Setup\RegistrationMeta.cs" />
<Compile Include="Tasks\TypeScannerTask.cs" />
<Compile Include="Extensions\XmlManifest2012ExtensionReader.cs" />
<Compile Include="Process\TopologicalSort.cs" />
<Compile Include="Trust\Filters\FuncContractFilter.cs" />
<Compile Include="Trust\Filters\ContractFilter.cs" />
<Compile Include="Trust\Filters\ITrustFilter.cs" />
<Compile Include="Trust\ITrustManager.cs" />
<Compile Include="Trust\Contexts\BoxesExtensions\TypeFromPackageTrustContext.cs" />
<Compile Include="Trust\Contexts\TrustContext.cs" />
<Compile Include="Trust\Filters\TrustFilterBase.cs" />
<Compile Include="Trust\TrustManager.cs" />
</ItemGroup>
<ItemGroup>
<None Include="BoxesExtensionManifest.xsd">
Expand Down
193 changes: 69 additions & 124 deletions src/Boxes.Integration/BoxesWrapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,167 +13,112 @@
// limitations under the License.
namespace Boxes.Integration
{
using System.Collections.Generic;
using System.Linq;
using ContainerSetup;
using Boxes.Tasks;
using Discovering;
using Factories;
using InternalIoc;
using Loading;
using Process;
using Setup;
using Tasks;
using Trust;

/// <summary>
/// Wrapper around Boxes, and extends it with an IoC container
/// this wrapper of boxes.core, this will integrate the features of boxes with an IoC container
/// </summary>
public abstract class BoxesWrapperBase<TContainer> : IBoxesWrapper
/// <typeparam name="TBuilder">the type used to build registrations</typeparam>
/// <typeparam name="TContainer">the type of the container, this will be used to resolve the instances</typeparam>
/// <remarks>
/// do not remove the TContainer this is used with the extension methods and with the other classes in the system</remarks>
public abstract class BoxesWrapperBase<TBuilder, TContainer> : IBoxesWrapper<TBuilder>
{
//TODO: look at disabling registrations http://ayende.com/blog/2792/introducing-monorail-hotswap
//TODO: look at disabling registrations (controllable in a module)
//http://ayende.com/blog/2792/introducing-monorail-hotswap
//issue is around the containers, a subset allow to deletions of registrations
//an other way is to restart the app and only register the required packages with the IoC
//the second way can be supported by coding a module
//favoured way, use of child container, will need to re-initialise the container (delete, create a new one)
//favored way, use of child container, will need to re-initialise the container (delete, create a new one)

//TODO: migrations
//TODO: migrations (possible in a module)
//updates of a module will require a restart, currently the Loaders do not support
//app domains. they do offer a level of isolation

//TODO: Multi-tenancy
//TODO: Multi-tenancy (possible in a module)
//use child containers to handle tenants. implement a IProcess (consider PLinq) to register
//the correct packages with the correct child container.

/// <summary>
/// the main process line, add tasks to this, and they will be executed
/// in the order defined by <see cref="IProcessOrder"/>
/// </summary>
private readonly PipelineExecutorWrapper<ProcessPackageContext> _processPipeline = new PipelineExecutorWrapper<ProcessPackageContext>();
/// <summary>
/// this is the pre-process pipeline, however its not recommended to use this one.
/// </summary>
private readonly PipelineExecutorWrapper<ProcessPackageContext> _preProcessPipeline = new PipelineExecutorWrapper<ProcessPackageContext>();
//TODO: consider how to admin an application (need feedback)

private readonly BoxesSetup _setup;
//TODO: events (possible in a module)

protected BoxesWrapperBase(TContainer container)
private IPackageScanner _defaultPackageScanner;
private ILoader _loader;
private readonly TaskRunner<Package> _extensionRunner;
private readonly LoaderFactory _loaderFactory;
private readonly IInternalContainer _internalContainer;

protected BoxesWrapperBase()
{
Container = container;
Initalise(container);
_setup = new BoxesSetup(this);
BoxesIntegrationSetup = new BoxesIntergrationSetup(_setup);
}
_internalContainer = new InternalInternalContainer();
PackageRegistry = new PackageRegistry();
_extensionRunner = new TaskRunner<Package>(new ExtendBoxesTask(_internalContainer));
_loaderFactory = new LoaderFactory();

public virtual PackageRegistry PackageRegistry { get { return DependencyResolver.Resolve<PackageRegistry>(); } }
public virtual IBoxesContainerSetup BoxesContainerSetup { get { return DependencyResolver.Resolve<IBoxesContainerSetup>(); } }
public virtual IBoxesIntegrationSetup BoxesIntegrationSetup { get; private set; }
//setup the internal IoC
_internalContainer.Add<IProcessOrder, TopologicalProcessOrder>();
_internalContainer.Add(typeof(IIocSetup<>), typeof(IocSetup<>));
_internalContainer.Add<ITrustManager, TrustManager>();

/// <summary>
/// Dev notes in the remarks
/// </summary>
/// <remarks>
/// Register with the IoC and Set the following properties
/// <see cref="DependencyResolver"/>,
/// <see cref="IBoxesWrapper.BoxesContainerSetup"/>,
/// and <see cref="IBoxesWrapper.PackageRegistry"/>
/// </remarks>
/// <param name="container">the container which was passed to the ctor</param>
protected abstract void Initalise(TContainer container);
_internalContainer.Add<LoaderFactory, LoaderFactory>();
_internalContainer.setInstance(typeof(LoaderFactory), _loaderFactory);

/// <summary>
/// access to the container (kernel in the case of Ninject)
/// </summary>
protected virtual TContainer Container { get; private set; }
Initialize(_internalContainer);
}

/// <summary>
/// The Dependency resolver
/// </summary>
public abstract IDependencyResolver DependencyResolver { get; }
public PackageRegistry PackageRegistry { get; private set; }

/// <summary>
/// Sets up the <see cref="IPackageScanner"/> and <see cref="ILoader"/>
/// Dev notes in the remarks
/// </summary>
/// <remarks>
/// Register the <see cref="IPackageScanner"/> and <see cref="ILoader"/>
/// </remarks>
/// <typeparam name="TLoader"></typeparam>
/// <param name="defaultPackageScanner"></param>
public abstract void Setup<TLoader>(IPackageScanner defaultPackageScanner)
where TLoader : ILoader;

public virtual void DiscoverPackages(IPackageScanner packageScanner)
public void Setup<TLoader>(IPackageScanner defaultPackageScanner) where TLoader : ILoader
{
_defaultPackageScanner = defaultPackageScanner;
_loader = _loaderFactory.CreateLoader<TLoader>(PackageRegistry);
}

public void DiscoverPackages(IPackageScanner packageScanner)
{
PackageRegistry.DiscoverPackages(packageScanner);
}

public virtual void DiscoverPackages()
public void DiscoverPackages()
{
PackageRegistry.DiscoverPackages(DependencyResolver.Resolve<IPackageScanner>());
PackageRegistry.DiscoverPackages(_defaultPackageScanner);
}

public virtual void LoadPackages()
public void LoadPackages()
{
//TODO:review this method
//there are a number of phases
//1. Extensions
//2. Filter and organise packages
//3. IoC registrations
//4. PreProcess
//5. Process

//only process newly loaded packages
//each is a phase has to be isolated, as they may depend on
//one another
var loader = new LoaderProxy(DependencyResolver.Resolve<ILoader>());
var loader = new LoaderProxy(_loader);
PackageRegistry.LoadPackages(loader);

//process extensions first (in complete, before running the rest of the package or process)
_setup.ExtensionRunner.Execute(loader.Packages).Force();

//TODO: push the following into a separate interface

//filter out the packages which are not in use.
IEnumerable<Package> filteredPackages =
_setup.GlobalPackagesFilter == null
? loader.Packages
: _setup.GlobalPackagesFilter.FilterPackages(loader.Packages);

//get process Order
IEnumerable<Package> packages = _setup.ProcessOrder.Arrange(filteredPackages);

//find the types in each package
var processContexts =
packages.Select(
x =>
{
IPackageTypesFilter typesFilter;
if (!_setup.PackageTypesFilters.TryGetValue(x.Name, out typesFilter))
{
typesFilter = _setup.DefaultPackageTypesFilter;
}

var context = new ProcessPackageContext(x, typesFilter.FilterTypes(x));
return context;
}).ToList(); //save the result, as we may need multiple iterations

//we need to register all the types with the underlying IoC first
_setup.IocTask.UpdateTasksAsRequired();
_setup.IocRunner.Execute(processContexts).Force();

//any pre-processing, hopefully there is none! as it is not recommended
if (_setup.PreProcesTasks.Count > 0)
{
_preProcessPipeline.UpdateTasksAsRequired(_setup.PreProcesTasks);
_preProcessPipeline.Execute(processContexts).Force();
}

//finally run the Setup and boot up of all the newly found packages
//(tying to process them together, package by package)
if (_setup.ProcesTasks.Count > 0)
{
_processPipeline.UpdateTasksAsRequired(_setup.ProcesTasks);
_processPipeline.Execute(processContexts).Force();
}
var processOrder = _internalContainer.Resolve<IProcessOrder>();
var arrangedPackages = processOrder.Arrange(loader.Packages);

//process extensions first (completely, before running the rest of the package or process)
_extensionRunner.Execute(arrangedPackages).Force();
}

public T GetService<T>()
{
return _internalContainer.Resolve<T>();
}


public virtual void Dispose()
{
_internalContainer.Dispose();
}

public abstract void Dispose();
/// <summary>
/// setup boxes integration with the IoC implementation (register types with the internal IoC)
/// </summary>
protected abstract void Initialize(IInternalContainer internalContainer);

}
}
41 changes: 0 additions & 41 deletions src/Boxes.Integration/ContainerSetup/BoxesContainerSetupBase.cs

This file was deleted.

Loading

0 comments on commit aebf88f

Please sign in to comment.