-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A start of the API refactoring (Breaking changes)
Please read all of the obsolete comments ( in most cases it is a rename ) note: there are some spelling corrections note: the Registration class is being obsoleted, and replaced with a very similar RegisterBase class, in each implementation of integration such as Boxes.Windsor, they should supply their own Register implementation. This was to provide a better and strongly class/experience
- Loading branch information
Showing
11 changed files
with
257 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
namespace Boxes.Integration.ContainerSetup | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// This class provides a mechanism to setup the registration of types with the underlying IoC. | ||
/// </summary> | ||
public interface IRegister | ||
{ | ||
/// <summary> | ||
/// meta information about the registration | ||
/// </summary> | ||
RegistrationMeta RegistrationMeta { get; } | ||
} | ||
|
||
/// <summary> | ||
/// This class provides a mechanism to setup the registration of types with the underlying IoC. | ||
/// </summary> | ||
/// <typeparam name="TScope">The signature for the scope/lifestyle</typeparam> | ||
/// <typeparam name="TConfiguration">the IoC direct configuration for the current registration</typeparam> | ||
public interface IRegister<TScope, TConfiguration> : IRegister | ||
{ | ||
/// <summary> | ||
/// apply a filter (pattern) to find which types this registration will apply too | ||
/// </summary> | ||
/// <param name="where">the pattern to find the types this registration applies too</param> | ||
IRegister<TScope, TConfiguration> Where(Predicate<Type> where); | ||
|
||
/// <summary> | ||
/// which contracts to associate the current type with | ||
/// </summary> | ||
/// <param name="contracts">select the appropriate contracts to register this class with</param> | ||
IRegister<TScope, TConfiguration> AssociateWith(Contracts contracts); | ||
|
||
/// <summary> | ||
/// which contracts to associate the current type with | ||
/// </summary> | ||
/// <param name="contracts">provide a list of contracts to associate the current type with</param> | ||
IRegister<TScope, TConfiguration> AssociateWith(Func<Type, IEnumerable<Type>> contracts); | ||
|
||
/// <summary> | ||
/// which contracts to associate the current type with | ||
/// </summary> | ||
/// <param name="contracts">provide a list of contracts to associate the current type with</param> | ||
IRegister<TScope, TConfiguration> AssociateWith(IEnumerable<Type> contracts); | ||
|
||
/// <summary> | ||
/// supply a ctor to use, apply this in the Configure Method, as this will allow direct access | ||
/// to the actual IoC's registration | ||
/// </summary> | ||
/// <param name="factoryMethod">the ctor to use</param> | ||
[Obsolete("not all IoC's support this", true)] | ||
IRegister<TScope, TConfiguration> Ctor(Func<object> factoryMethod); | ||
|
||
/// <summary> | ||
/// the life style of the type (scope and lifestyle are considered to be the same thing at this point) | ||
/// </summary> | ||
/// <param name="lifeStyle">the life style to use</param> | ||
IRegister<TScope, TConfiguration> LifeStyle(TScope lifeStyle); | ||
|
||
/// <summary> | ||
/// the scope of the type (scope and lifestyle are considered to be the same thing at this point) | ||
/// </summary> | ||
/// <param name="scope">the scope to use</param> | ||
IRegister<TScope, TConfiguration> Scope(TScope scope); | ||
|
||
/// <summary> | ||
/// direct access to the IoC's registration, Recommended for the more advanced setup's | ||
/// </summary> | ||
/// <param name="cfg">ioc's registration</param> | ||
IRegister<TScope, TConfiguration> Configure(Action<RegisterContext<TConfiguration>> cfg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
namespace Boxes.Integration.ContainerSetup | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public abstract class RegisterBase<TScope, TConfiguration> : IRegister<TScope, TConfiguration> | ||
{ | ||
protected RegistrationMeta _meta = new RegistrationMeta(); | ||
|
||
public RegistrationMeta RegistrationMeta { get { return _meta; } } | ||
|
||
public virtual IRegister<TScope, TConfiguration> Where(Predicate<Type> where) | ||
{ | ||
_meta.Where += where; | ||
return this; | ||
} | ||
|
||
public IRegister<TScope, TConfiguration> AssociateWith(Contracts contracts) | ||
{ | ||
switch (contracts) | ||
{ | ||
case Contracts.AllInterfaces: | ||
_meta.With = type => type.AllInterfaces(); | ||
break; | ||
case Contracts.FirstInterface: | ||
_meta.With = type => new[] { (type.FirstInterface() ?? type) }; | ||
break; | ||
case Contracts.SelfOnly: | ||
_meta.With = type => new[] { type }; | ||
break; | ||
case Contracts.SelfAndAllInterfaces: | ||
_meta.With = type => type.SelfAndAllInterfaces(); | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException("contracts"); | ||
} | ||
return this; | ||
} | ||
|
||
public IRegister<TScope, TConfiguration> AssociateWith(Func<Type, IEnumerable<Type>> contracts) | ||
{ | ||
_meta.With = contracts; | ||
return this; | ||
} | ||
|
||
public IRegister<TScope, TConfiguration> AssociateWith(IEnumerable<Type> contracts) | ||
{ | ||
_meta.With = type => contracts; | ||
return this; | ||
} | ||
|
||
|
||
public IRegister<TScope, TConfiguration> Ctor(Func<object> factoryMethod) | ||
{ | ||
_meta.FactoryMethod = factoryMethod; | ||
return this; | ||
} | ||
|
||
public IRegister<TScope, TConfiguration> LifeStyle(TScope lifeStyle) | ||
{ | ||
_meta.LifeStyle = lifeStyle; | ||
return this; | ||
} | ||
|
||
public IRegister<TScope, TConfiguration> Scope(TScope scope) | ||
{ | ||
_meta.LifeStyle = scope; | ||
return this; | ||
} | ||
|
||
public IRegister<TScope, TConfiguration> Configure(Action<RegisterContext<TConfiguration>> cfg) | ||
{ | ||
_meta.Configurations.Add(o => cfg((RegisterContext<TConfiguration>)o)); | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Boxes.Integration.ContainerSetup | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// a register context holds all the information required for someone to have complete control | ||
/// over a single types registration. | ||
/// </summary> | ||
/// <typeparam name="TConfiguration">the underlying IoC registration type</typeparam> | ||
public class RegisterContext<TConfiguration> | ||
{ | ||
/// <summary> | ||
/// the configuration of the underlying IoC registration | ||
/// </summary> | ||
public TConfiguration Configuration { get; set; } | ||
|
||
/// <summary> | ||
/// the type the configuration is for | ||
/// </summary> | ||
public Type Type { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.