The ServiceLocator in Catel can be set up from configuration file.
Importing IoC configuration section
The first step to setup the service locator from the configuration file is import the custom section type Catel.IoC.IoCConfigurationSection from Catel.Core. The following example shows how to import this configuration section and make it available for the configuration file as ioc:
Configuring a service locator from the default configuration
It's possible add more than one service locator configuration to the configuration file but you must specify an unique name. If a name of a service locator configuration is not specified then the name default is assigned. By default such configuration supports dependency injection.
To configure a service locator from the default service locator configuration use the following code:
Configuring a service locator from a named configuration
The following configuration file is a full example on how write more than one service locator configuration:
To configure a service locator from a named configuration use the following code:
You should also note the options setup if the container in order to support dependency injection and the registration type (a.k.a instantiation style) and the tag for each registration.