Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public class MyService
{
    public void SomeMethod()
	{
        // If you need to create a type with the current scope type factory
		var typeFactory = this.GetTypeFactory();
 
        // If you need to register a type with the current scope service locator
        var serviceLocator = this.GetServiceLocator();
 
        // If you need to resolve a type with the current scope and the type is not injected via dependency injection
        var dependencyResolver = this.GetDependencyResolver();
	}
}

Replacing the default components

By default, Catel provides very fast and functional implementations of the component interfaces. It is possible though that one needs to use a different container than the specified ones.

Note

Note that when any component is replaced, it must be registered with the other instances that are already running. Catel cannot do this automatically because it is not aware how other (customized) components interact or require registration.

Replacing the default ServiceLocator

...

Code Block
var serviceLocator = new MyCustomServiceLocator();
var dependencyResolver = new CatelDependencyResolver(serviceLocator);
var typeFactory = new TypeFactory(dependencyResolver);
 
IoCConfiguration.DefaultServiceLocator = serviceLocator;
IoCConfiguration.DefaultDependencyResolver = dependencyResolver;
IoCConfiguration.DefaultTypeFactory = typeFactory;
Note

Note that Catel registers it's own services as soon as the assembly is loaded by the .NET runtime. If a custom ServiceLocator is used, these services have to be registered again. Catel provides helper classes for this by naming convention:

Code Block
var serviceLocator = new MyCustomServiceLocator();
 
// Core elements
CoreModule.RegisterServices(serviceLocator);
MVVMModule.RegisterServices(serviceLocator);
 
// Extensions
ExtensionsPrismModule.RegisterServices(serviceLocator);
ExtensionsMementoModule.RegisterServices(serviceLocator);

Replacing the default TypeFactory

...

Code Block
var typeFactory = new MyCustomTypeFactory(IoCConfiguration.DefaultDependencyResolver);

IoCConfiguration.DefaultTypeFactory = typeFactory;

Replacing the default DependencyResolver

...

Code Block
var dependencyResolver = new CatelDependencyResolver(IoCConfiguration.DefaultServiceLocator);
var typeFactory = new TypeFactory(dependencyResolver);

IoCConfiguration.DefaultDependencyResolver = dependencyResolver;
IoCConfiguration.DefaultTypeFactory = typeFactory;