-
Notifications
You must be signed in to change notification settings - Fork 10
Conditional resolution
Peter Csajtai edited this page Feb 11, 2016
·
19 revisions
If you want to specify in which cases you want to inject some special dependencies, you can use the conditional resolution feature of Stashbox. ##Parent type filter
class Wulfgar : IBarbarian
{
[Dependency]
public IWeapon Weapon { get; set; }
}
container.PrepareType<IWeapon, AegisFang>().WhenDependantIs<Wulfgar>().Register();
The constraint above indicates that Stashbox will choose the
AegisFang
implementation of theIWeapon
interface whenWulfgar
is being resolved.
##Attribute filter If you set attribute filter for your registration, Stashbox will inject it only, if the dependency is decorated with that attribute:
class NeutralGoodAttribute : Attribute { }
class ChaoticEvilAttribute : Attribute { }
class Drizzt : IDrow
{
[Dependency, NeutralGood]
public IPatron Patron { get; set; }
}
class Yvonnel : IDrow
{
[Dependency, ChaoticEvil]
public IPatron Patron { get; set; }
}
container.PrepareType<IPatron, Mielikki>().WhenHas<NeutralGood>().Register();
container.PrepareType<IPatron, Lolth>().WhenHas<ChaoticEvil>().Register();
- 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