-
Notifications
You must be signed in to change notification settings - Fork 530
Changes in Ninject 3
Scott Xu edited this page Apr 7, 2014
·
10 revisions
Link to thread announcing Ninject 3 RC Availability
- New Features and changes of Ninject 3.0
- Ninject.Extensions.Factory introduction
- Ninject constructor selection preview
Ninject 2.2 has an issue where the constructor it selects can change. Here is an example:
class Foo
{
Foo() {}
Foo(Bar bar) {}
}
kernel.Get<Foo>(); // The Foo() constructor is called by Ninject 2.2 the first time Foo is resolved
kernel.Get<Bar>();
kernel.Get<Foo>(); // The Foo(Bar bar) constructor is called since Ninject 2.2 now knows about Bar.
To resolve this issue, Ninject 3 will now choose the constructor with the most arguments it knows how to create but implicit self bindings are considered as unknown! Add an explicit self binding in case it matters for the selection.
class Foo
{
Foo() {}
Foo(Bar bar) {}
}
kernel.Get<Foo>(); // The Foo() constructor is called by Ninject 3.0
kernel.Get<Bar>();
kernel.Get<Foo>(); // The Foo() constructor is called by Ninject 3.0
Bottom line – if you are upgrading to Ninject 3.0 from Ninject 2.2, check your bound types to make sure the correct constructor is used!
Go back to the Home page or the Table of Contents
Continue reading: Why Use Ninject?
Licensed under Apache 2 License
Contents
- Home
- Why Use Ninject
- Getting Started
- Dependency Injection By Hand
- Dependency Injection With Ninject
- Injection Patterns
- Multi Injection
- Object Scopes
- Modules and the Kernel
- Providers, Factory Methods and the Activation Context
- The Activation Process
- How Injection Works
- Contextual Binding
- Conventions-Based Binding