Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simplify Default Scope implementation
  • Loading branch information
remogloor committed May 23, 2012
1 parent c0e9bc3 commit b60dcc2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 23 deletions.
1 change: 1 addition & 0 deletions ReleaseNotes.txt
@@ -1,4 +1,5 @@
Version 3.0.1
- Add: The default scope can be changed in the NinjectSettings
- Change: Open generics can now be passed to WhenInjectedInto
- Bugfix: Fixed race condition in the GarbageCollectionCachePruner

Expand Down
12 changes: 1 addition & 11 deletions src/Ninject/Planning/Bindings/Binding.cs
Expand Up @@ -27,21 +27,11 @@ public class Binding : IBinding
/// </summary>
/// <param name="service">The service that is controlled by the binding.</param>
public Binding(Type service)
: this(service, StandardScopeCallbacks.Transient)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Binding"/> class.
/// </summary>
/// <param name="service">The service that is controlled by the binding.</param>
/// <param name="scopeCallback">The scope callback for the service.</param>
public Binding(Type service, Func<IContext, object> scopeCallback)
{
Ensure.ArgumentNotNull(service, "service");

this.Service = service;
this.BindingConfiguration = new BindingConfiguration(scopeCallback);
this.BindingConfiguration = new BindingConfiguration();
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Ninject/Planning/Bindings/BindingBuilder.cs
Expand Up @@ -51,6 +51,7 @@ public BindingBuilder(IBindingConfiguration bindingConfiguration, IKernel kernel
this.BindingConfiguration = bindingConfiguration;
this.Kernel = kernel;
this.ServiceNames = serviceNames;
this.BindingConfiguration.ScopeCallback = kernel.Settings.DefaultScopeCallback;
}

/// <summary>
Expand Down
8 changes: 1 addition & 7 deletions src/Ninject/Planning/Bindings/BindingConfiguration.cs
Expand Up @@ -36,18 +36,12 @@ public class BindingConfiguration : IBindingConfiguration
/// Initializes a new instance of the <see cref="BindingConfiguration"/> class.
/// </summary>
public BindingConfiguration()
: this(StandardScopeCallbacks.Transient) { }

/// <summary>
/// Initializes a new instance of the <see cref="BindingConfiguration"/> class.
/// </summary>
public BindingConfiguration(Func<IContext, object> scopeCallback)
{
this.Metadata = new BindingMetadata();
this.Parameters = new List<IParameter>();
this.ActivationActions = new List<Action<IContext, object>>();
this.DeactivationActions = new List<Action<IContext, object>>();
this.ScopeCallback = scopeCallback ?? StandardScopeCallbacks.Transient;
this.ScopeCallback = StandardScopeCallbacks.Transient;
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/Ninject/Syntax/BindingRoot.cs
Expand Up @@ -51,7 +51,7 @@ public IBindingToSyntax<T> Bind<T>()
{
Type service = typeof(T);

var binding = new Binding(service, KernelInstance.Settings.DefaultScopeCallback);
var binding = new Binding(service);
this.AddBinding(binding);

return new BindingBuilder<T>(binding, this.KernelInstance, service.Format());
Expand All @@ -65,7 +65,7 @@ public IBindingToSyntax<T> Bind<T>()
/// <returns>The fluent syntax</returns>
public IBindingToSyntax<T1, T2> Bind<T1, T2>()
{
var firstBinding = new Binding(typeof(T1), KernelInstance.Settings.DefaultScopeCallback);
var firstBinding = new Binding(typeof(T1));
this.AddBinding(firstBinding);
this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration));
var servceNames = new[] { typeof(T1).Format(), typeof(T2).Format() };
Expand All @@ -82,7 +82,7 @@ public IBindingToSyntax<T> Bind<T>()
/// <returns>The fluent syntax</returns>
public IBindingToSyntax<T1, T2, T3> Bind<T1, T2, T3>()
{
var firstBinding = new Binding(typeof(T1), KernelInstance.Settings.DefaultScopeCallback);
var firstBinding = new Binding(typeof(T1));
this.AddBinding(firstBinding);
this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration));
this.AddBinding(new Binding(typeof(T3), firstBinding.BindingConfiguration));
Expand All @@ -101,7 +101,7 @@ public IBindingToSyntax<T> Bind<T>()
/// <returns>The fluent syntax</returns>
public IBindingToSyntax<T1, T2, T3, T4> Bind<T1, T2, T3, T4>()
{
var firstBinding = new Binding(typeof(T1), KernelInstance.Settings.DefaultScopeCallback);
var firstBinding = new Binding(typeof(T1));
this.AddBinding(firstBinding);
this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration));
this.AddBinding(new Binding(typeof(T3), firstBinding.BindingConfiguration));
Expand All @@ -124,7 +124,7 @@ public IBindingToSyntax<object> Bind(params Type[] services)
throw new ArgumentException("The services must contain at least one type", "services");
}

var firstBinding = new Binding(services[0], KernelInstance.Settings.DefaultScopeCallback);
var firstBinding = new Binding(services[0]);
this.AddBinding(firstBinding);

foreach (var service in services.Skip(1))
Expand Down

0 comments on commit b60dcc2

Please sign in to comment.