This project is read-only.

Creating a Dependency Resolver

The easiest way to create a new instance of a dependency resolver is to load the configuration of a named dependency resolver from a configuration file and then call the Create method of the DependencyResolverManager class, passing in the config.

    IDependencyResolverConfiguration config = 

    IDependencyResolver dependencyResolver = DependencyResolverManager.Create(config);

The code snippet above loads the configuration for a dependency resolver named "MyResolver" from the default .NET config file (e.g. App.config or Web.config) using the ConfigurationLoader helper class. The configuration is then passed as an argument to the DependencyResolverManager class' Create method which will then use the specified configuration to create a new instance of the dependency resolver which is assigned to the dependencyResolver variable.

Once you have an instance of IDependencyResolver you may resolve your objects. Typically, you only need to create a single dependency resolver instance for the lifetime of the application. Most of the overhead in Drill is in the creation of a new dependency resolver instance, therefore you do not want to create dependency resolvers more than is necessary. Typically, you create a single instance at application start-up and store the reference for future use, possibly in a member of a static class. You may also opt to register the instance in the DependencyResolverManager using the CreateAndRegister or Register methods, but this is not required. The dependency resolver implementations included in Drill are thread-safe. Custom implementations may not be, so be careful.

Please read the Configuration section for more information about the Drill configuration system and the available options to load configuration from various sources aside from the simple case shown above.

There are other ways to create a new dependency resolver instance, but this is the recommended method. Other methods are planned to be documented at a later date when advanced topics are covered.

Last edited Nov 24, 2012 at 8:08 PM by wreynolds, version 4


No comments yet.