Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added IHaveBindingRoot interface ... #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Ninject/IHaveBindingRoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Ninject.Syntax;

namespace Ninject
{
/// <summary>
/// Indicates the object has a reference to a <see cref="IBindingRoot"/>.
/// </summary>
public interface IHaveBindingRoot
{
/// <summary>
/// Gets the associated binding root.
/// </summary>
IBindingRoot BindingRoot { get; }
}
}
1 change: 1 addition & 0 deletions src/Ninject/Ninject.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<Compile Include="GlobalKernelRegistration.cs" />
<Compile Include="GlobalKernelRegistrationModule.cs" />
<Compile Include="IBindingPrecedenceComparer.cs" />
<Compile Include="IHaveBindingRoot.cs" />
<Compile Include="IHaveNinjectComponents.cs" />
<Compile Include="IHaveNinjectSettings.cs" />
<Compile Include="IInitializable.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Ninject/Ninject.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<Compile Include="Components\INinjectComponent.cs" />
<Compile Include="Components\NinjectComponent.cs" />
<Compile Include="IBindingPrecedenceComparer.cs" />
<Compile Include="IHaveBindingRoot.cs" />
<Compile Include="IHaveNinjectComponents.cs" />
<Compile Include="IHaveNinjectSettings.cs" />
<Compile Include="IInitializable.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Ninject/Ninject.WinRT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Compile Include="GlobalKernelRegistration.cs" />
<Compile Include="GlobalKernelRegistrationModule.cs" />
<Compile Include="IBindingPrecedenceComparer.cs" />
<Compile Include="IHaveBindingRoot.cs" />
<Compile Include="IHaveNinjectComponents.cs" />
<Compile Include="IHaveNinjectSettings.cs" />
<Compile Include="IInitializable.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Ninject/Ninject.Wpa81.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="Components\INinjectComponent.cs" />
<Compile Include="Components\NinjectComponent.cs" />
<Compile Include="IBindingPrecedenceComparer.cs" />
<Compile Include="IHaveBindingRoot.cs" />
<Compile Include="IHaveNinjectComponents.cs" />
<Compile Include="IHaveNinjectSettings.cs" />
<Compile Include="IInitializable.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Ninject/Ninject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<Compile Include="GlobalKernelRegistration.cs" />
<Compile Include="GlobalKernelRegistrationModule.cs" />
<Compile Include="IBindingPrecedenceComparer.cs" />
<Compile Include="IHaveBindingRoot.cs" />
<Compile Include="IHaveNinjectComponents.cs" />
<Compile Include="IHaveNinjectSettings.cs" />
<Compile Include="IInitializable.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Ninject/Ninject.iOS-Unified.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<Compile Include="GlobalKernelRegistration.cs" />
<Compile Include="GlobalKernelRegistrationModule.cs" />
<Compile Include="IBindingPrecedenceComparer.cs" />
<Compile Include="IHaveBindingRoot.cs" />
<Compile Include="IHaveNinjectComponents.cs" />
<Compile Include="IHaveNinjectSettings.cs" />
<Compile Include="IInitializable.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Ninject/Ninject.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="GlobalKernelRegistration.cs" />
<Compile Include="GlobalKernelRegistrationModule.cs" />
<Compile Include="IBindingPrecedenceComparer.cs" />
<Compile Include="IHaveBindingRoot.cs" />
<Compile Include="IHaveNinjectComponents.cs" />
<Compile Include="IHaveNinjectSettings.cs" />
<Compile Include="IInitializable.cs" />
Expand Down
22 changes: 14 additions & 8 deletions src/Ninject/Planning/Bindings/BindingBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public class BindingBuilder
/// <param name="bindingConfiguration">The binding to build.</param>
/// <param name="settings">The ninject configuration settings.</param>
/// <param name="serviceNames">The names of the services.</param>
public BindingBuilder(IBindingConfiguration bindingConfiguration, INinjectSettings settings, string serviceNames)
public BindingBuilder(IBindingConfiguration bindingConfiguration, IBindingRoot bindingRoot, INinjectSettings settings, string serviceNames)
{
this.BindingConfiguration = bindingConfiguration;
this.BindingRoot = bindingRoot;
this.ServiceNames = serviceNames;
this.BindingConfiguration.ScopeCallback = settings.DefaultScopeCallback;
}
Expand All @@ -54,6 +55,11 @@ public BindingBuilder(IBindingConfiguration bindingConfiguration, INinjectSettin
/// </summary>
public IBindingConfiguration BindingConfiguration { get; private set; }

/// <summary>
/// Gets the associated binding root.
/// </summary>
public IBindingRoot BindingRoot { get; private set; }

/// <summary>
/// Gets the names of the services.
/// </summary>
Expand Down Expand Up @@ -81,7 +87,7 @@ protected IBindingWhenInNamedWithOrOnSyntax<T> InternalTo<T>(Type implementation
StandardProvider.AssignProviderCallback(this.BindingConfiguration, implementation);
this.BindingConfiguration.Target = BindingTarget.Type;

return new BindingConfigurationBuilder<T>(this.BindingConfiguration, this.ServiceNames);
return new BindingConfigurationBuilder<T>(this.BindingConfiguration, this.BindingRoot, this.ServiceNames);
}

/// <summary>
Expand All @@ -97,7 +103,7 @@ protected IBindingWhenInNamedWithOrOnSyntax<TImplementation> InternalToConfigura
this.BindingConfiguration.Target = BindingTarget.Constant;
this.BindingConfiguration.ScopeCallback = StandardScopeCallbacks.Singleton;

return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.ServiceNames);
return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.BindingRoot, this.ServiceNames);
}

/// <summary>
Expand All @@ -112,7 +118,7 @@ protected IBindingWhenInNamedWithOrOnSyntax<TImplementation> InternalToMethod<TI
this.BindingConfiguration.ProviderCallback = ctx => callbackProvider;
this.BindingConfiguration.Target = BindingTarget.Method;

return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.ServiceNames);
return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.BindingRoot, this.ServiceNames);
}

/// <summary>
Expand All @@ -126,7 +132,7 @@ protected IBindingWhenInNamedWithOrOnSyntax<TImplementation> InternalToProvider<
this.BindingConfiguration.ProviderCallback = ctx => provider;
this.BindingConfiguration.Target = BindingTarget.Provider;

return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.ServiceNames);
return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.BindingRoot, this.ServiceNames);
}

/// <summary>
Expand All @@ -142,7 +148,7 @@ protected IBindingWhenInNamedWithOrOnSyntax<TImplementation> ToProviderInternal<
this.BindingConfiguration.ProviderCallback = ctx => ctx.Kernel.Get<TProvider>();
this.BindingConfiguration.Target = BindingTarget.Provider;

return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.ServiceNames);
return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.BindingRoot, this.ServiceNames);
}

/// <summary>
Expand All @@ -157,7 +163,7 @@ protected IBindingWhenInNamedWithOrOnSyntax<T> ToProviderInternal<T>(Type provid
this.BindingConfiguration.ProviderCallback = ctx => ctx.Kernel.Get(providerType) as IProvider;
this.BindingConfiguration.Target = BindingTarget.Provider;

return new BindingConfigurationBuilder<T>(this.BindingConfiguration, this.ServiceNames);
return new BindingConfigurationBuilder<T>(this.BindingConfiguration, this.BindingRoot, this.ServiceNames);
}

/// <summary>
Expand All @@ -179,7 +185,7 @@ protected IBindingWhenInNamedWithOrOnSyntax<TImplementation> InternalToConstruct
this.BindingConfiguration.Target = BindingTarget.Type;
this.AddConstructorArguments(ctorExpression, newExpression.Parameters[0]);

return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.ServiceNames);
return new BindingConfigurationBuilder<TImplementation>(this.BindingConfiguration, this.BindingRoot, this.ServiceNames);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3,T4}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class BindingBuilder<T1, T2, T3, T4> : BindingBuilder, IBindingToSyntax<T
/// <param name="bindingConfigurationConfiguration">The binding to build.</param>
/// <param name="settings">The ninject configuration settings.</param>
/// <param name="serviceNames">The names of the services.</param>
public BindingBuilder(IBindingConfiguration bindingConfigurationConfiguration, INinjectSettings settings, string serviceNames)
: base(bindingConfigurationConfiguration, settings, serviceNames)
public BindingBuilder(IBindingConfiguration bindingConfigurationConfiguration, IBindingRoot bindingRoot, INinjectSettings settings, string serviceNames)
: base(bindingConfigurationConfiguration, bindingRoot, settings, serviceNames)
{
}
#pragma warning restore 1584
Expand Down
4 changes: 2 additions & 2 deletions src/Ninject/Planning/Bindings/BindingBuilder{T1,T2,T3}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class BindingBuilder<T1, T2, T3> : BindingBuilder, IBindingToSyntax<T1, T
/// <param name="bindingConfigurationConfiguration">The binding to build.</param>
/// <param name="settings">The ninject configuration settings.</param>
/// <param name="serviceNames">The names of the services.</param>
public BindingBuilder(IBindingConfiguration bindingConfigurationConfiguration, INinjectSettings settings, string serviceNames)
: base(bindingConfigurationConfiguration, settings, serviceNames)
public BindingBuilder(IBindingConfiguration bindingConfigurationConfiguration, IBindingRoot bindingRoot, INinjectSettings settings, string serviceNames)
: base(bindingConfigurationConfiguration, bindingRoot, settings, serviceNames)
{
}
#pragma warning restore 1584
Expand Down
4 changes: 2 additions & 2 deletions src/Ninject/Planning/Bindings/BindingBuilder{T1,T2}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class BindingBuilder<T1, T2> : BindingBuilder, IBindingToSyntax<T1, T2>
/// <param name="bindingConfigurationConfiguration">The binding to build.</param>
/// <param name="settings">The ninject configuration settings.</param>
/// <param name="serviceNames">The names of the services.</param>
public BindingBuilder(IBindingConfiguration bindingConfigurationConfiguration, INinjectSettings settings, string serviceNames)
: base(bindingConfigurationConfiguration, settings, serviceNames)
public BindingBuilder(IBindingConfiguration bindingConfigurationConfiguration, IBindingRoot bindingRoot, INinjectSettings settings, string serviceNames)
: base(bindingConfigurationConfiguration, bindingRoot, settings, serviceNames)
{
}
#pragma warning restore 1584
Expand Down
6 changes: 3 additions & 3 deletions src/Ninject/Planning/Bindings/BindingBuilder{T1}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class BindingBuilder<T1> : BindingBuilder, IBindingToSyntax<T1>
/// <param name="binding">The binding to build.</param>
/// <param name="settings">The ninject configuration settings.</param>
/// <param name="serviceNames">The names of the services.</param>
public BindingBuilder(IBinding binding, INinjectSettings settings, string serviceNames)
: base(binding.BindingConfiguration, settings, serviceNames)
public BindingBuilder(IBinding binding, IBindingRoot bindingRoot, INinjectSettings settings, string serviceNames)
: base(binding.BindingConfiguration, bindingRoot, settings, serviceNames)
{
this.Binding = binding;
}
Expand All @@ -64,7 +64,7 @@ public IBindingWhenInNamedWithOrOnSyntax<T1> ToSelf()
StandardProvider.AssignProviderCallback(this.BindingConfiguration, this.Binding.Service);
this.Binding.Target = BindingTarget.Self;

return new BindingConfigurationBuilder<T1>(this.Binding.BindingConfiguration, this.ServiceNames);
return new BindingConfigurationBuilder<T1>(this.Binding.BindingConfiguration, this.BindingRoot, this.ServiceNames);
}

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion src/Ninject/Planning/Bindings/BindingConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ public class BindingConfigurationBuilder<T> : IBindingConfigurationSyntax<T>
/// </summary>
public IBindingConfiguration BindingConfiguration { get; private set; }

/// <summary>
/// Gets the associated binding root.
/// </summary>
public IBindingRoot BindingRoot { get; private set; }

/// <summary>
/// Initializes a new instance of the BindingBuilder&lt;T&gt; class.
/// </summary>
/// <param name="bindingConfiguration">The binding configuration to build.</param>
/// <param name="serviceNames">The names of the configured services.</param>
public BindingConfigurationBuilder(IBindingConfiguration bindingConfiguration, string serviceNames)
public BindingConfigurationBuilder(IBindingConfiguration bindingConfiguration, IBindingRoot bindingRoot, string serviceNames)
{
this.BindingConfiguration = bindingConfiguration;
this.BindingRoot = bindingRoot;
this.serviceNames = serviceNames;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ninject/ReadonlyKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private List<IBinding> GetBindingsFromFirstResolverThatReturnsAtLeastOneBinding(
private void AddReadonlyKernelBinding<T>(T readonlyKernel, Multimap<Type, IBinding> bindings)
{
var binding = new Binding(typeof(T));
new BindingBuilder<T>(binding, this.Settings, typeof(T).Format()).ToConstant(readonlyKernel);
new BindingBuilder<T>(binding, null, this.Settings, typeof(T).Format()).ToConstant(readonlyKernel);
bindings.Add(typeof(T), binding);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Ninject/Syntax/BindingRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IBindingToSyntax<T> Bind<T>()
var binding = new Binding(service);
this.AddBinding(binding);

return new BindingBuilder<T>(binding, this.Settings, service.Format());
return new BindingBuilder<T>(binding, this, this.Settings, service.Format());
#endif
}

Expand All @@ -77,7 +77,7 @@ public IBindingToSyntax<T1, T2> Bind<T1, T2>()
this.AddBinding(new Binding(typeof(T2), firstBinding.BindingConfiguration));
var serviceNames = new[] { typeof(T1).Format(), typeof(T2).Format() };

return new BindingBuilder<T1, T2>(firstBinding.BindingConfiguration, this.Settings, string.Join(", ", serviceNames));
return new BindingBuilder<T1, T2>(firstBinding.BindingConfiguration, this, this.Settings, string.Join(", ", serviceNames));
#endif
}

Expand All @@ -99,7 +99,7 @@ public IBindingToSyntax<T1, T2, T3> Bind<T1, T2, T3>()
this.AddBinding(new Binding(typeof(T3), firstBinding.BindingConfiguration));
var serviceNames = new[] { typeof(T1).Format(), typeof(T2).Format(), typeof(T3).Format() };

return new BindingBuilder<T1, T2, T3>(firstBinding.BindingConfiguration, this.Settings, string.Join(", ", serviceNames));
return new BindingBuilder<T1, T2, T3>(firstBinding.BindingConfiguration, this, this.Settings, string.Join(", ", serviceNames));
#endif
}

Expand All @@ -123,7 +123,7 @@ public IBindingToSyntax<T1, T2, T3, T4> Bind<T1, T2, T3, T4>()
this.AddBinding(new Binding(typeof(T4), firstBinding.BindingConfiguration));
var serviceNames = new[] { typeof(T1).Format(), typeof(T2).Format(), typeof(T3).Format(), typeof(T4).Format() };

return new BindingBuilder<T1, T2, T3, T4>(firstBinding.BindingConfiguration, this.Settings, string.Join(", ", serviceNames));
return new BindingBuilder<T1, T2, T3, T4>(firstBinding.BindingConfiguration, this, this.Settings, string.Join(", ", serviceNames));
#endif
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public IBindingToSyntax<object> Bind(params Type[] services)
this.AddBinding(new Binding(service, firstBinding.BindingConfiguration));
}

return new BindingBuilder<object>(firstBinding, this.Settings, string.Join(", ", services.Select(service => service.Format()).ToArray()));
return new BindingBuilder<object>(firstBinding, this, this.Settings, string.Join(", ", services.Select(service => service.Format()).ToArray()));
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ninject/Syntax/IBindingSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Ninject.Syntax
/// <summary>
/// Used to define a basic binding syntax builder.
/// </summary>
public interface IBindingSyntax : IHaveBindingConfiguration, IFluentSyntax
public interface IBindingSyntax : IHaveBindingConfiguration, IHaveBindingRoot, IFluentSyntax
{
}
}