Questions tagged [contextual-binding]
22 questions
0
votes
7 answers
Two types use a subdependency - how to use different implementations
Say we register two types, RootA and RootB, that each have a dependency on ISubdependency.
Sharing the same subdependency implementation is easy:
services.AddSingleton();
services.AddSingleton

Timo
- 7,992
- 4
- 49
- 67
0
votes
1 answer
Bind interface to multiple concrete implementation with constructor argument
I am trying to do contextual binding but not able to bind concrete implementation interface as constructor argument.
Ninject version: 3.2.0.0
My structure is as follows:
INotifier
1. XNotifier
2. YNotifier
IPublisher
1. APublisher
2.…

AnandSonake
- 567
- 1
- 8
- 19
0
votes
1 answer
NInject contextual binding When method is called too many times
interface IWarrior
{
}
class Samurai : IWarrior
{
}
public class Program
{
public static void Main(string[] args)
{
var kernel = new StandardKernel();
kernel.Bind().To().When(i =>
{
…

Lev
- 3,719
- 6
- 41
- 56
0
votes
1 answer
Ninject binding based on object's property? Convention or contextual binding?
I have an interface:
public interface IInterface
{
string Get(obj o);
}
and I have the 2 classes:
public class C1 : IInterface
{
string Get(obj o);
}
public class C2 : IInterface
{
string Get(obj o);
}
I'd like to send in o and then have Ninject…

user3328656
- 13
- 2
0
votes
1 answer
Ninject Binding "all inheriting from x"
Pretty usual scenario:
public class A { }
public class B:A {}
public class C:A {}
I really wonder if it is possible to create Ninject Bindings that resolve all inheriting from A like the following:
Bind().ToMethod(ctx =>…

Sebastian Edelmeier
- 4,095
- 3
- 39
- 60
0
votes
1 answer
Ninject Get WhenTargetHas
So I'm using Ninject, specifically the contextual binding as follows :
Bind().ToMethod(x => FirstBlahProvider.Instance.GiveMeOne()).WhenTargetHas().InRequestScope();
Bind().ToMethod(x =>…

Tim Butterfield
- 565
- 5
- 24
0
votes
1 answer
Drupal7: How could Contextual filter: Content: Nid return the TNID instead of NID in Views3
I have a Contextual filter: Content: Nid in Views3 that I want to return the TNID instead of the NID When the filter value is NOT available.
I tried
$node=node_load($argument);
$argument = $node->tnid;
return $argument;…

headkit
- 3,307
- 4
- 53
- 99