Skip to content

Changes in Ninject 4

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

Changes

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.

Read-only kernel

TODO Scott

Private member injection

Even though injection into private members is generally considered to be a bad practice, Ninject provides 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.

.NET Native / AOT

By default, Ninject now uses expression trees for injection instead of LCG which ensures compatibility with .NET Native (and other AOT runtimes).

The UseReflectionBasedInjection setting can be used to switch to reflection based injection.

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>.

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)
  • Request for List<T> takes implicit binding into account (#263)
  • Service is cached for scope when member injection fails (#262)
  • Building with NO_LCG results in test failure (#219)
  • Deadlock between ICache.Clear() and ICache.TryGet(IContext context) (#182)
  • Not compatible with UWP using .NET Native tool chain (#271)