-
Notifications
You must be signed in to change notification settings - Fork 29
Configuring Bindings
The final step is to customise the configuration of the created bindings using the Configure
method. It uses exactly the same syntax as that provided by Ninject core to configure single bindings. Please refer to the core documentation for more detailed information regarding the available options.
The Configure
method has two overloads. The first overload supplies just the binding to your Action
. This overload is used in most cases:
.Configure(b => b.InSingletonScope());
The second overload additionally supplies the Component being projected as the second parameter to your Action
. This can be used in case the binding needs to take into account some information about the Component. e.g., the following configuration uses the component name to name the binding.
.Configure((b, c) => b.InSingletonScope().Named(c.Name));
Sometimes it is necessary to add some additional configuration for certain types. e.g., if you have a Component that fits the same general rule other as a set of Components in all respects except that it needs an additional constructor argument, then you can use a configuration sequence such as this:
.Configure(b => b.InSingletonScope()) .ConfigureFor<SpecialService>(b => b.WithConstructorArgument("arg", 0))
This means all the components are configured are singletons. Additionally, SpecialService
will get 0
injected into its constructor parameter arg
. The special configuration specified in the ConfigureFor
is applied in addition to the base configuration. Note that because in the case SpecialService
both configuration Actions get run, it is possible to override a part of the base configuration defined in the base Configure
section by using the same option method with different options (or using a different mutually exclusive option) in the ConfigureFor
action.
End: This concludes the Ninject Conventions Extension wiki
Back: Projecting Services to Bind
Ninject project home: Ninject