-
Notifications
You must be signed in to change notification settings - Fork 29
Configuring Bindings
The final step is to configure the created bindings. Using the Configure method. It uses exactly the same syntax as provided by Ninject core to configure single bindings. Please see this documentation for more information about binding configuration.
The Configure method has two overloads. The first overload gives you just the binding. This overload is used in most cases:
.Configure(b => b.InSingletonScope());
The second overload gives you additionally the component. This can be used in case the binding needs 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 service that behaves exaxtly the same way as other services but it needs an additional constructor argument then you can specify this like this:
.Configure(b => b.InSingletonScope())
.ConfugureFor<SpecialService>(b => b.WithConstructorArgument("arg", 0));
This means all the currently created services are singletons. But additionally the SpecialService will get injected 0 into its constructor parameter arg. The special configuration is an addition to the default configuration. But it can also be used to override a part of the default configuration.
Back: Projecting Services to Bind
Home: Home