-
Notifications
You must be signed in to change notification settings - Fork 10
Conventional resolution
When you enable the conventional resolution with the TreatParameterAndMemberNameAsDependencyName()
configuration option, the container will treat the member and method parameter names as their dependency identifier.
First, you have to enable the conditional resolution:
var container = new StashboxContainer(c => c.TreatParameterAndMemberNameAsDependencyName());
Let's say, you have a service class like this:
class Drizzt
{
public Drizzt(IWeapon icingdeath, IWeapon twinkle)
{ }
}
Then, if you register your weapon classes with names like this:
container.Register<Drizzt>()
.Register<IWeapon, Icingdeath>(c => c.WithName("icingdeath"))
.Register<IWeapon, Twinkle>(c => c.WithName("twinkle"));
Then, when you resolve Drizzt
, the container will choose that registration which has a matching name to the related parameter.
You can achieve the same as above with member injection as well.
With a class like this:
class Drizzt
{
public IWeapon Icingdeath { get; set; }
public IWeapon Twinkle { get; set; }
}
And with the following registration part:
container.Register<Drizzt>(c => c.WithAutoMemberInjection())
.Register<IWeapon, Icingdeath>(c => c.WithName("Icingdeath"))
.Register<IWeapon, Twinkle>(c => c.WithName("Twinkle"));
The container will choose the appropriate weapon by matching the property names to the dependency names.
- Service registration
- Factory registration
- Assembly registration
- Composition
- Fluent registration api
- Service resolution
- Resolution by attributes
- Conventional resolution
- Delegate resolution
- Conditional resolution
- Multi resolution
- Lifetimes
- Generics
- Generic wrappers
- Decorators
- Resolvers
- Scopes
- Container configuration
- Container diagnostics
- Exceptions