Skip to content

Changes in Ninject 4

Gert Driesen edited this page Mar 21, 2019 · 12 revisions

Framework support

As of Ninject 4 we only support the following target frameworks:

  • .NET Framework 4.6 (and higher)
  • .NET Standard 2.0

Performance

A major focus point for Ninject 4 is moving the needle for both performance and memory usage.

TODO Link to a benchark, and images showing the advancements.

Fixes

  • A StackOverflowException is thrown when type is a self-bindable, but the registered binding does not match (#341)
  • Attempt to resolve an unbound generic type definition results in an IndexOutOfRangeException (#340
  • Bind/Rebind to a constant List always returns an empty list (#333)

Changes

Private member injection

Even though injection into private members is generally considered to be a bad practice, Ninject has provide knobs to enable private constructor, method and property injection.

To encourage you to move away from private member injection, both the InjectNonPublic and InjectParentPrivateProperties properties on (I)NinjectSettings are marked obsolete as of this release.

Unless we receive strong user feedback to keep this feature, support for private member injection will be removed in the next major release.

Property injection

A new PropertyInjection property on (I)NinjectSettings has been introduced to allow one to disable property injection.

For those using only constructor or method injection, disabling property injection yields a minor performance bump.

By default, property injection remains enabled.

Method injection

A new MethodInjection property on (I)NinjectSettings has been introduced to allow one to disable method injection.

For those using only constructor or property injection, disabling method injection yields a minor performance bump.

By default, method injection remains enabled.

Extensibility API changes

This section provides a list of (breaking) API changes that we introduced. These changes only affect extensibility authors.

IBindingResolver

Changed return value of IBindingResolver (and implementing classes) from IEnumerable<IBinding> to ICollection<IBinding>.

ISelector

Changed return value of ISelector.SelectConstructorsForInjection(Type type) (and implementing classes) from IEnumerable<ConstructorInfo> to ConstructorInfo[].

INinjectSettings

The T Get<T>(string key, T defaultValue) and void Set(string key, object value) methods have been removed from INinjectSettings.

IKernelConfiguration

The GetBindings(Type service) method now returns IBinding[] instead of IEnumerable<IBinding>.

IReadOnlyKernel

The GetBindings(Type service) method now returns IBinding[] instead of IEnumerable<IBinding>.

KernelBase

The GetBindings(Type service) method now returns IBinding[] instead of IEnumerable<IBinding>.