-
Notifications
You must be signed in to change notification settings - Fork 13
Getting started
In order to use XML configuration you need to create one or more XML files that contain an XML configuration module and publish them with your solution. Once you have created these XML modules you need to tell the kernel to load them using the Load method:
this.Kernel.Load("myXmlConfigurationModule.xml");
The xml file must contain an xml configuration module like shown this the following example:
<module name="myXmlConfigurationModule">
<bind service="MyNamespace.IMyService, MyAssembly"
to="MyNamespace.MyServiceImplementation, MyAssembly" />
<bind service="MyNamespace.IMyOtherService, MyAssembly"
to="MyNamespace.MyOtherServiceImplementation, MyAssembly" />
</module>
The xml configuration must contain the root element module. This is used to define the unique name of the module using its name attribute. The module element contains one or more bind elements to configure the bindings.
Each bind element defines one Ninject binding. It is comparable to a call to kernel.Bind<IService>().To<Service>()
.
The service attribute defines the servce type of the binding. It is equivalent to the kernel.Bind()
method.
The to attribute defines the implementation type of the binding. It is equivalent to the .To<Service>()
method.
Alternatively to the "to" attibute you can use the "toProvider" attribute to define a Ninject provider instead of an implementation type. It is equivalent to the .ToProvider<ServiceProvider>()
method.
In case you want to configure a named binding you can add an optional "name" attribute to the binding to define the name of the binding.
A binding can contain an optional scope attribute that defines the scope. It defaults to transient if none is declared. The following values are allowed:
-
transient: is equivalent to
InTransientScope()
-
singleton: is equivalent to
InSingletonScope()
-
thread: is equivalent to
InThreadScope()
-
request: is equivalent to
InRequestScope()
this option requires that you are using the Ninject.Web.Common.Xml extension
All the types configured by the bindings must be defined as assembly qualified names: http://msdn.microsoft.com/de-de/library/system.type.assemblyqualifiedname.aspx
Continue reading: Metadata