Questions tagged [contextual-binding]
22 questions
7
votes
1 answer
Contextual bindings with Ninject 2.0
In Ninject 1.0 I had following binding definitions:
Bind().To().Only(When.Context.Variable("variable").EqualTo(true));
Bind().To();
Given such bindings I had calls:
ITarget target =…

Przemaas
- 841
- 11
- 23
4
votes
1 answer
Ninject Contextual Binding at RunTime
I am trying to understand Ninject Contextual Binding. I understand the scenarios where I know my context at design time. e.g. I understand that I can use Named Attributes to Bind the DB object to a mock DB when I want to use it in a test class and…

Yasir
- 1,595
- 5
- 23
- 42
3
votes
1 answer
Ninject Binding Constraint that searches up to find a type
I've got a class hierarchy like this (simplified):
class Connection
{
}
interface IService
{
}
class ServiceImplementation : IService
{
public ServiceImplementation(Connection)
{
}
}
interface IConnectionConfiguration
{
…

icedtoast
- 128
- 2
- 10
3
votes
0 answers
Laravel contextual binding to be more specific to methods rather then class only
I am trying to understand laravel bind.
let's say, I have UploadFileController.php
Route::post('/upload/images', 'UploadFilesController@uploadImage');
Route::post('/upload/pdf', 'UploadFilesController@uploadPdf');
then in the controller,
class…

Mohsin Younas
- 324
- 4
- 12
3
votes
2 answers
Parameter based bindings in ninject 2.0
I want to use conditional binding in ninject, based on passed parameters. I have something like below:
public class Subject
{
}
public interface ITarget
{
}
public class Target1 : ITarget
{
}
public class Target2 : ITarget
{
}
And now I need to…

Przemaas
- 841
- 11
- 23
3
votes
1 answer
What causes the Ninject.Activation.IRequest Target property to be null
Probably a simple question, but I did not find anything in the documentation or on SO that directly answers it.
I had to work with the Ninject When(Func condition) extension method for the first time, and got hung up for a bit with…

Lucas
- 8,035
- 2
- 32
- 45
2
votes
1 answer
tdd ioc container ninject contextual binding
I need some help with using contextual binding with ninject
I Have something like this :
public interface ISound
{
String Sound();
}
public class Cat : Animal
{
private string category;
private ISound sound;
public Cat(ISound…

Alexandra Tupu
- 143
- 10
2
votes
0 answers
Ninject issue with contextual binding and Lazy
Ninject doesn't seem to correctly use WhenInjectedInto contstraint while also using Lazy. Check the following example. The OnLandAttack and the OnLandAttackLazy should each be using the Samurai instance. But the Lazy version ends up with the…

walts81
- 21
- 1
1
vote
1 answer
How use Laravel Contextual Binding for Logger channels?
In Laravel documentation I see example:
$this->app->when(PhotoController::class)
->needs(Filesystem::class)
->give(function () {
return Storage::disk('local');
…

4n70wa
- 337
- 4
- 19
1
vote
0 answers
\GuzzleHttp\Client resolving hangs if contextual binding is done using make() or makeWith()
I am writing a simple API-wrapper and this wrapper needs the configured GuzzleHttp\Client instance as a dependency.
use GuzzleHttp\Client;
class Api {
private $client;
public function __construct(Client $client)
{
$this->client…

Alexander K
- 21
- 2
1
vote
1 answer
How to avoid needing a reference to Ninject on an injection target assembly when using contextual binding
I'm looking at contextual binding with Ninject. This is for when you have multiple implementations of some abstraction, and context in the injection target class determines which of those implementations is injected.
In the documentation, the…

rory.ap
- 34,009
- 10
- 83
- 174
1
vote
1 answer
Autofac vs Ninject contextual binding?
1) Autofac and Ninject, which one is better in contextual binding?
2) With Ninject, I can bind to types in a specific namespace:
Bind().To().When(context =>
context.ParentContext.Binding.Service.Namespace == "MyProject.Common");
Can I do…
user593358
1
vote
1 answer
How can I retrieve the attribute and the properties when using Ninject contextual binding?
I have a constructor
[ReadFromFile(@"C:\SampleData\login.json")]
public AccountController(IReadRepository repository, string filePath) : base(repository)
{
}
The attribute contains a property "FilePath".
public string FilePath…

SamIAm
- 2,241
- 6
- 32
- 51
1
vote
1 answer
Ninject contextual binding for 2+ dependent classes w/ different names for same constructor param
Having trouble figuring out how to manage contextual binding in the scenario where two classes have the same underlying interface dependency, but each class ctor's parameter is named differently. Pseudo code below to demonstrate my situation:
…

Brett Rossier
- 3,420
- 3
- 27
- 36
0
votes
0 answers
Laravel Contextual binding same class with different type of classes in different places
I want to bind same class with different type of classes depending on Controller name
, for example
$this->app->bind(BaseFormRequest::class,function(){
return new CategoryFormRequest;
…

Hassan Elshazly Eida
- 605
- 5
- 20