Questions tagged [ninject-3]
17 questions
40
votes
1 answer
Is it possible to bind different interfaces to the same instance of a class implementing all of them?
I have the following (simplified) situation: I have two interfaces
interface IAmAnInterface
{
void DoSomething();
}
and
interface IAmAnInterfaceToo
{
void DoSomethingElse();
}
and a class implementing both:
class IAmAnImplementation:…

Silas
- 1,140
- 11
- 12
12
votes
2 answers
Using default parameter values with Ninject 3.0
I have a class with a constructor having a parameter with a default value. With Ninject 2.2, it would honor the [Optional] attribute and work fine with no binding defined against a constructor declared like so:
public EmployeeValidator([Optional]…

The Davester
- 498
- 3
- 8
11
votes
4 answers
Ninject ToFactory works in Resharper unit tests, but not NCrunch
I'm using Ninject.Extensions.Factory with Ninject 3 to create a factory, which creates different types of IFoo based on the string provided to the factory. I've got a passing unit test, but oddly, only in the Resharper test runner. In the NCrunch…

harriyott
- 10,505
- 10
- 64
- 103
9
votes
2 answers
Disable implicit binding/injection of non explicitly bound classes in Ninject 2+
If you request an unbound object from NInject, then the default behaviour is (if a suitable constructor is available) appears to be to create an instance of the appropriate object.
I'd like to disable this behaviour (I had a difficult to debug issue…

Jeff Foster
- 43,770
- 11
- 86
- 103
4
votes
2 answers
Ninject 3.0 MVC kernel scan not working
What happened to kernel.Scan in Ninject 3.0?
kernel.Scan(scanner =>
{
scanner.FromAssembliesMatching("LR.Service.*");
scanner.FromAssembliesMatching("LR.Repository.*");
…

Yogurt The Wise
- 4,379
- 4
- 34
- 42
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
3
votes
1 answer
Convention based binding in Ninject 3.0
I'm trying to setup Ninject on my new project and I want to scan assembilies using convetions so that
IFoo
will automatically resolve to
IBar
All the samples and documentation describes using this approach
kernel.Scan(...)
while the Ninject 3…

Ryan Vice
- 2,133
- 3
- 23
- 33
2
votes
2 answers
Ninject Conventions with multiple Froms
I have some code in a NinjectModule that sets up Mock bindings for all interfaces in multiple assemblies. Ninject 2 allowed me to call the From() methods multiple times inside the Scan lambda:
Kernel.Scan(scanner =>
{
string first =…

MikeWyatt
- 7,842
- 10
- 50
- 71
2
votes
0 answers
Ninject ASP.NET extension throwing TypeLoadException
I'm trying to use Ninject 3 in an ASP.NET webforms application. We've been using it without the Ninject.Web extension for a while by creating a new injection kernel everywhere we needed one. It didn't occur to me until now that that's not the…

Mark R
- 341
- 3
- 10
1
vote
1 answer
Ninject 3 multiple bindings
My question is really a repeat of an old question posted here:
Ninject 2.2 multiple bindings
It seems someone was going to deal with this back in 2011. Does anyone know if there is some way to turn off such warnings in Ninject? Or some other…

Matt
- 6,787
- 11
- 65
- 112
1
vote
1 answer
Ninject Conventions with Ninject Factory Extension To Bind Multiple Types To One Interface
I'm trying to expand on the scenario asked in the SO question titled Ninject Factory Extension Bind Multiple Concrete Types To One Interface by using Ninject Conventions for convention-based binding of the ICar implementations.
I'm working off the…

Jeff
- 2,191
- 4
- 30
- 49
1
vote
1 answer
Ninject specify binding scope of non referenced component
I have a library that's meant to be used both on desktop apps and web apps.
This library has a reference to an external data-access component that on desktop should be bound as singleton and on web should be on request scope.
Desktop project…

David Lay
- 2,956
- 4
- 27
- 48
1
vote
1 answer
upgrade Ninject v2 to v3 with .NET 4 System.ServiceProcess.ServiceBase
I am attempting to use Ninject v3 to test a web service hosted within a .NET4 windows service ( System.ServiceProcess.ServiceBase ).
I create MyServerModule : NinjectModule , and within Load() I conditionally bind my interfaces to runtime objects…

BaltoStar
- 8,165
- 17
- 59
- 91
1
vote
2 answers
Injecting a concrete implementation of a WCF ServiceContract based off value in a config file dymamically
Say I have the following service contract and two concrete implementations:
[OperationContract]
public interface ISearchService {
public ICollection Search(string text);
}
[SearchServiceBehaviour]
public class SolrSearchService :…

Soliah
- 1,376
- 2
- 13
- 24
0
votes
1 answer
Disposing of out-of-scoped objects in Ninject kernel
I'm trying to figure out how the kernel disposed of objects it has in it. For example, the following code creates two scopes and asserts that the same object is resolves when the scope if the same, a different one when it's different.
[Test]
public…

BanksySan
- 27,362
- 33
- 117
- 216