Home

Castle Stronghold

Table of contents

  • 1 Setting dependencies on the handler
  • 2 Specifing dependencies upon request
  • 3 Order of precedence

Suppling inline dependencies during construction

The usual way the MicroKernel satisfy components dependencies is by looking for other components registered or using the configuration. Along with this default way to obtain dependencies values, there are two more which can be useful for some advanced scenarios.

Through the handler: you can set dependencies values on the handler for the component that has the dependencies.

Upon request: When you request a component from the container, you can pass a dictionary with dependencies values.

Setting dependencies on the handler

If you want to add dependencies directly to the handle, use the method RegisterCustomDependencies exposed by the IKernel interface.


Hashtable deps = new Hashtable();
deps.Add("cc", new CompC(12));
deps.Add("myArgument", "value");

kernel.RegisterCustomDependencies("compb", deps);

CompB compb = kernel[typeof(CompB)] as CompB;

Specifing dependencies upon request

In the same way, you can use the method Resolve to pass a dictionary with the dependencies and its values.


Hashtable deps = new Hashtable();
deps.Add("cc", new CompC(12));
deps.Add("myArgument", "value");

CompB compb = kernel.Resolve(typeof(CompB), deps) as CompB;

Order of precedence

The precedence is important. The first object considered when a dependency resolution is taking place is the dictionary passed to the Resolve method (if any). Then the dictionary set on the handler. Then any custom ISubDependencyResolve registered on the dependency resolver. Finally the resolver goes the default way to try to resolve the dependency requested.

Google
Search WWW Search castleproject.org