Skip to content

Commit

Permalink
container support
Browse files Browse the repository at this point in the history
added abstract to wrapper to be implemented by container
couple of other refactorings
  • Loading branch information
dbones committed Aug 1, 2013
1 parent 84c570e commit fa97a7a
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 91 deletions.
6 changes: 3 additions & 3 deletions src/Boxes.Integration/Boxes.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
<ItemGroup>
<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\IApplicationContainerSetup.cs" />
<Compile Include="Setup\IRegistrationTaskMapper.cs" />
<Compile Include="Setup\ITenantContainerSetup.cs" />
<Compile Include="Setup\DefaultContainerSetup.cs" />
<Compile Include="Exceptions\ServiceTypeDoesNotMatchInstanceException.cs" />
<Compile Include="Exceptions\FailedTrustException.cs" />
<Compile Include="Trust\Contexts\BoxesExtensions\AssemblyFromPackageTrustContext.cs" />
Expand All @@ -68,7 +68,7 @@
<Compile Include="Factories\FuncCreateLoader.cs" />
<Compile Include="Factories\ICreateLoader.cs" />
<Compile Include="Factories\IDependencyResolverFactory.cs" />
<Compile Include="Factories\IIoCFactory.cs" />
<Compile Include="Factories\IIocFactory.cs" />
<Compile Include="Factories\LoaderFactory.cs" />
<Compile Include="ObjectExtensions.cs" />
<Compile Include="Process\TopologicalProcessOrder.cs" />
Expand Down
55 changes: 27 additions & 28 deletions src/Boxes.Integration/BoxesWrapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.
namespace Boxes.Integration
{
using System;
using Boxes.Tasks;
using Discovering;
using Factories;
Expand All @@ -23,25 +22,33 @@ namespace Boxes.Integration
using Tasks;
using Trust;

/// <summary>
/// this wrapper of boxes.core, this will integrate the features of boxes with an IoC container
/// </summary>
/// <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
//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.

//TODO: consider how to admin an application
//TODO: consider how to admin an application (need feedback)

//TODO: events
//TODO: events (possible in a module)

private IPackageScanner _defaultPackageScanner;
private ILoader _loader;
Expand All @@ -55,6 +62,16 @@ protected BoxesWrapperBase()
PackageRegistry = new PackageRegistry();
_extensionRunner = new TaskRunner<Package>(new ExtendBoxesTask(_internalContainer));
_loaderFactory = new LoaderFactory();

//setup the internal IoC
_internalContainer.Add<IProcessOrder, TopologicalProcessOrder>();
_internalContainer.Add(typeof(IIocSetup<>), typeof(IocSetup<>));
_internalContainer.Add<ITrustManager, TrustManager>();

_internalContainer.Add<LoaderFactory, LoaderFactory>();
_internalContainer.setInstance(typeof(LoaderFactory), _loaderFactory);

Initialize(_internalContainer);
}

public PackageRegistry PackageRegistry { get; private set; }
Expand Down Expand Up @@ -97,29 +114,11 @@ public virtual void Dispose()
{
_internalContainer.Dispose();
}

}


public class App
{
public void Main()
{
//IBoxesWrapper<> boxes = null;
////boxes.BoxesIntegrationSetup
////how do we want to configure?

//boxes.Setup<IsolatedLoader>(new PackageScanner("folder"));
//boxes.DiscoverPackages();
//boxes.LoadPackages();



//boxes.EnablePackages("", "", "", "", ""); //auto detect the tenant
//boxes.DependencyResolver.Resolve<Object>();
}

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

}

}
2 changes: 1 addition & 1 deletion src/Boxes.Integration/Factories/FuncCreateLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Boxes.Integration.Factories
{
using System;
using Boxes.Loading;
using Loading;

/// <summary>
/// creates a Loader, based on a Func which is passed in via the ctor
Expand Down
2 changes: 1 addition & 1 deletion src/Boxes.Integration/Factories/IIoCFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Boxes.Integration.Factories
/// <summary>
/// create instances of containers as required
/// </summary>
public interface IIoCFactory<TBuilder, TContainer>
public interface IIocFactory<TBuilder, TContainer>
{

/// <summary>
Expand Down
51 changes: 51 additions & 0 deletions src/Boxes.Integration/Factories/IIocSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2012 - 2013 dbones.co.uk (David Rundle)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.
namespace Boxes.Integration.Factories
{
/// <summary>
/// A Setup to use with the IoC (this should be injected into the <see cref="IIocFactory{TBuilder,TContainer}"/>)
/// </summary>
/// <typeparam name="TBuilder">the IoC setup</typeparam>
public interface IIocSetup<in TBuilder>
{
/// <summary>
/// configure the main container
/// </summary>
/// <param name="builder">the main container builder, (this should be before any registrations)</param>
void Configure(TBuilder builder);

/// <summary>
/// configure a child container
/// </summary>
/// <param name="builder">the child builder, (this should be before any registrations)</param>
void ConfigureChild(TBuilder builder);
}

/// <summary>
/// does nothing, vanilla setup of the ioc
/// </summary>
/// <typeparam name="TBuilder"></typeparam>
public class IocSetup<TBuilder> : IIocSetup<TBuilder>
{
public void Configure(TBuilder builder)
{

}

public void ConfigureChild(TBuilder builder)
{

}
}
}
16 changes: 0 additions & 16 deletions src/Boxes.Integration/IBoxesWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,6 @@ public interface IBoxesWrapper<TBuilder> : IDisposable
/// </summary>
public static class BoxesWrapperExtensions
{
/// <summary>
/// A mechanism to handle type registration with the Tenant(s) IoC container.
/// </summary>
public static ITenantContainerSetup<TBuilder> Registrations<TBuilder>(this IBoxesWrapper<TBuilder> boxes)
{
return boxes.GetService<ITenantContainerSetup<TBuilder>>();
}

/// <summary>
/// A mechanism to handle type registration with the underlying Global/Parent IoC container.
/// </summary>
public static IApplicationContainerSetup<TBuilder> GlobalRegistrations<TBuilder>(this IBoxesWrapper<TBuilder> boxes)
{
return boxes.GetService<IApplicationContainerSetup<TBuilder>>();
}

/// <summary>
/// the trust manager being used by boxes.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Boxes.Integration/InternalContainerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Boxes.Integration
/// <summary>
/// some extensions for the internal container
/// </summary>
internal static class InternalContainerExtensions
public static class InternalContainerExtensions
{
public static void Add<TContract, TService>(this IInternalContainer internalContainer) where TService : TContract
{
Expand Down
2 changes: 1 addition & 1 deletion src/Boxes.Integration/InternalIoc/IInternalContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Boxes.Integration.InternalIoc
/// <summary>
/// A simple internal container, which will manage the services available in Boxes.
/// </summary>
internal interface IInternalContainer : IDisposable
public interface IInternalContainer : IDisposable
{
void Add(Type contract, Type service);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public object Resolve(Type contract)
{
//no support for list or lazy, this is a simple internalContainer
Type[] genericArguments = contract.GetGenericArguments();
getServiceType = r => r.Service.MakeGenericType(genericArguments);
getServiceType = r => r.Service.IsGenericType ? r.Service.MakeGenericType(genericArguments) : r.Service;
contract = contract.GetGenericTypeDefinition();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
// limitations under the License.
namespace Boxes.Integration.Setup
{
//TODO:move into the base/default module

/// <summary>
/// the tenants container setup
/// </summary>
/// <typeparam name="TBuilder">the ioc builder class</typeparam>
public interface ITenantContainerSetup<TBuilder> : IContainerSetup<TBuilder> { }
public interface IDefaultContainerSetup<TBuilder> : IContainerSetup<TBuilder> { }


public class TenantContainerSetup<TBuilder> : ContainerSetupBase<TBuilder>, ITenantContainerSetup<TBuilder>
public class DefaultContainerSetup<TBuilder> : ContainerSetupBase<TBuilder>, IDefaultContainerSetup<TBuilder>
{
public TenantContainerSetup(IRegistrationTaskMapper<TBuilder> registrationTaskMapper) : base(registrationTaskMapper)
public DefaultContainerSetup(IRegistrationTaskMapper<TBuilder> registrationTaskMapper)
: base(registrationTaskMapper)
{
}
}
Expand Down
21 changes: 0 additions & 21 deletions src/Boxes.Integration/Setup/IApplicationContainerSetup.cs

This file was deleted.

15 changes: 2 additions & 13 deletions src/Boxes.Integration/Setup/IContainerSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ public interface IContainerSetup : IBoxesExtensionWithSetup
/// <param name="packageName">name of the package</param>
/// <returns>null if there is not filter</returns>
ITypeRegistrationFilter GetTypeRegistrationFilter(string packageName);


//void RegisterPreProcessTask(IBoxesTask<ProcessPackageContext> task);


//void RegisterProcessTask(IBoxesTask<ProcessPackageContext> task);
}


Expand All @@ -72,12 +66,7 @@ public interface IContainerSetup<TBuilder> : IContainerSetup
/// all the registration to run the types through
/// </summary>
IEnumerable<IBoxesTask<RegistrationContext<TBuilder>>> Registrations { get; }

//IEnumerable<IBoxesTask<ProcessPackageContext>> PreProcessTasks { get; }

//IEnumerable<IBoxesTask<ProcessPackageContext>> ProcessTasks { get; }



}


}
3 changes: 1 addition & 2 deletions src/Boxes.Integration/Setup/RegistrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ namespace Boxes.Integration.Setup
{
using System;

//TODO: keep an eye on this class, look at some profiling

//TODO: keep an eye on the use of this class, look at some profiling

/// <summary>
/// the context for the registration
Expand Down

0 comments on commit fa97a7a

Please sign in to comment.